开发者

JQuery remove last number of list items

I have a var containing a number and need to subtract this number from the total number of list items. Then I need to remove the end items in the list eg. Total = 20; Number of list items = 18; Final number = 2; Then remove the last 2 list items.

Thanks for any help.开发者_如何学JAVA


I'd use the :gt() selector.

$( 'li:gt(' + ( maxAllowed-1 ) + ')' ).remove();

Demo: http://jsfiddle.net/JAAulde/5GdQx/


$.slice(start, [end])

jQuery Documentation

UPDATE:

Example:

$('li').slice( -numToRemove ).remove();

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜