As a function with a little better handling of 0:
function insertAtIndex(i) {
if(i === 0) {
$("#controller").prepend("okay things");
return;
}
$("#controller > div:nth-child(" + (i) + ")").after("great things");
}
EDIT: Added parenthesis in the nth-child selector to avoid NaN errors. @hofnarwillie
function insertAtIndex(i) {
if(i === 0) {
$("#controller").prepend("okay things");
return;
}
$("#controller > div:nth-child(" + (i) + ")").after("great things");
}
window.doInsert = function(){
insertAtIndex(2);
}
Item 1
Item 2
Item 4
Item 5