Given a UL, how to remove all items after 5, if any?

With jQuery is there a way remove an LI items after position 6?


A way to dynamically remove items 6+ (6 & 7 in this case) and not break if there are less than 6 items? Any ideas? Thanks



$('ul li:gt(4)').remove();

PS: in your title you say "after 5" and "after 6" is in the question body. I've chosen the one from the title

Can be accomplished with an nth-child selector:

$( 'ul li:nth-child( n + 6 )' ).remove( );

Need Your Help

insert something into kill ring in Emacs

emacs elisp yank kill-ring

I want to write a function that will insert the file name of the current buffer into the kill ring so I can yank it to the terminal in another window. How can I programmatically insert a string int...

How to get user Names of domain in Sharepoint web part?

sharepoint visual-studio-2010

I want to get user names in active directory by using sharepoint webpart.