Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery select all children after nth-child

I am working with jquery and creating show hide lists, I need hide all the child list items that follow the 6th child in the ul. Normally I would do this by setting the height and then changing the height on click of a click, but for this to work I need to add overflow:hidden to my css, and this is not an option.

How would I get all the child list elements that are greater than the 7th child?

Something like,

$("ul li:6n").domeSomething()

like image 985
Udders Avatar asked Jun 10 '12 08:06

Udders


1 Answers

How would I get all the child list elements that are greater than the 7th child?

Select the element index = 7+

$("ul li:gt(6)").domeSomething()

:gt selector

The selector uses the zero base index:

Note that since JavaScript arrays use 0-based indexing, these selectors reflect that fact. This is why $('.myclass:gt(1)') selects elements after the second element in the document with the class myclass, rather than after the first. In contrast, :nth-child(n) uses 1-based indexing to conform to the CSS specification.

like image 125
gdoron is supporting Monica Avatar answered Sep 23 '22 20:09

gdoron is supporting Monica