tags:

views:

261

answers:

1
+5  A: 

You can use the greater-than/less-than selectors:

$("#someDiv p:lt(4)").hide(); /* hides 0, 1, 2, 3 */

That would hide all paragraphs less than the fifth. To determine whether or not there's 5 or more paragraphs, you'll check the length property:

if ($("#someDiv p").length > 5) {
  $("#someDiv p:gt(3)").hide(); /* hides 4, 5, 6... */
}
Jonathan Sampson
Thanks Jonathan..I want to Show the first four and I also do not know how many <p> are there in teh div..When I use this it does not work for some reason$("#someDiv p:not(:lt(4))").hide();
lols
You're making this too complicated. Don't use :not(:lt()) blah blah. Just use :gt(4) - that will select all elements with an index greater than 4.
Jonathan Sampson