开发者

jQuery pseudo classes

开发者 https://www.devze.com 2023-02-18 12:57 出处:网络
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

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

精彩评论

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