Select 2nd element of UL

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
dheeraja
Forum Commoner
Posts: 36
Joined: Tue Nov 09, 2010 11:03 pm

Select 2nd element of UL

Post by dheeraja »

Hello Guys,
I am using Jquery to show or hide element of <ul> with the following code:

Code: Select all

$('#menu ul:first').show();
or

Code: Select all

$('#menu ul:last').show();
but this will help me with only first & last element, if I want to do this with 2nd or 3rd then what I have to do??
Please help me..

Thanks in advance...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Select 2nd element of UL

Post by pickle »

The "eq" selector is what you want: http://api.jquery.com/eq-selector/

Code: Select all

$('#menu ul li:eq(1)').show()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply