Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 512
Zhen Avatar asked Nov 22 '11 17:11

Zhen


1 Answers

$(".topics .topic").slice(5).hide();

http://api.jquery.com/slice/

like image 128
ThiefMaster Avatar answered Nov 15 '22 04:11

ThiefMaster