How to select and hide all but first 5 elements in a HTML file (DOM)

Posted by Zhen on Stack Overflow See other posts from Stack Overflow or by Zhen
Published on 2011-11-22T17:42:04Z Indexed on 2011/11/22 17:51 UTC
Read the original article Hit count: 259

Filed under:
|
|
|
|

I am attempting to use coffeescript/jQuery to do the following:

1) Retrieve all the 'topics' displayed in the html (seen below)

2) Hide all the topics from display except for the first 5 listed.

enter image description here

I tried to do the following but is not working

//Retrieve the entire list of and hide all but the first 5 topics in the list
$(".topics .topic")[5..-1].hide()

Can someone advise me on how I can correctly retrieve the list of topics from the HTML document and subsequently hide ALL but the first 5 topics?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html