I got a variable called "nthchild" var nthchild = ($(ui.selected).index() + 1);
This gives me the nth-child of a list item with the class selected. I even log it in the console and it works fine. However when I try to use this variable but it doesn't work.
$("section:nth-child(" + nthchild + ")").style.marginTop = "200px";
So it should give the section a margin-top of 200px. But the console is giving me the error
Uncaught ReferenceError: nthchild is not defined
You can find my code on this codepen
$(function() {
$("#selectable").selectable();
});
$(function() {
$("#selectable").selectable({
selected: function(event, ui) {
var nthchild = ($(ui.selected).index() + 1);
console.log(nthchild);
}
});
});
$("section:nth-child(" + nthchild + ")").style.marginTop = "200px";