views:

81

answers:

3

I have the following HTML

<ul id="listing">
<li>...</li>
<li>...</li>
<li>...</li>
</ul>

How can I access the 2nd LI inner text?

Can I do

$("#listing li").[1].text()

If not, what is the sytax?

+8  A: 
$("#listing li:eq(1)").text();

More about the Index Selector at http://docs.jquery.com/Selectors/eq#index

Jonathan Sampson
+4  A: 

close

$("#listing li").eq(1).text()

http://docs.jquery.com/Traversing/eq

Brandon H
What you linked too show the following syntax -> $("#listing li:eq(1)").text();Does your syntax work (is supported). Your syntax makes more sense to me
BillyJ
did you read the other guys link? my link has $("div").eq(2).addClass("blue");
Brandon H
Does one version perform better than another?
BillyJ
okay this is promising... http://www.spadgos.com/?p=51seems like the eq() method is around five times faster than :eq() granted, it probably doesn't matter at all in your situation.
Brandon H
A: 

have a look at the eq selector in jquery

Yassir