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.
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();
May be if you try this:
var deleteIndex = 3;
$("ol li:eq(deleteIndex)").remove();
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.
It really works.
精彩评论