开发者

jQuery pseudo classes

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜