Reputation: 3536
Is this correct?
var deleteIndex = 3;
$("ol li:nth-child(deleteIndex)").remove();
For some reason, this doesn't seem to work. Executing this clears the whole list.
Upvotes: 0
Views: 228
Reputation: 14766
You need to use:
var deleteIndex = 3;
$("ol li:nth-child(" + deleteIndex + ")").remove();
so that deleteIndex is converted to 3. Or if 3 is a constant used only here, you could just use 3.
Upvotes: 0
Reputation: 36999
You are adding the literal text 'deleteIndex' into the jQuery selector rather than the number contained in the variable. Try this instead:
var deleteIndex = 3;
$("ol li:nth-child(" + deleteIndex + ")").remove();
Upvotes: 8
Reputation: 15070
May be if you try this:
var deleteIndex = 3;
$("ol li:eq(deleteIndex)").remove();
Upvotes: 0