bentley5
bentley5

Reputation: 83

Get the value text of a link starting from div

How do I get the text value of cp5 hello world by starting with the div MrJ.

<div id="MrJ">
<ul>
<li>
<a href="http://www.test.com/">h</a>
</li>
<li>
<a href="http://www.test.com/cp5/">cp5 hello world</a>
</li>
<li>subcat</li>
</ul>
</div>

This is where I'm at:

alert($('#MrJ').find('ul li').find('a:gt(1)');

Upvotes: 0

Views: 42

Answers (1)

Barmar
Barmar

Reputation: 781058

alert($('#MrJ ul li a:eq(1)').text());

First, you want :eq(1), not :gt(1), since the one you want is number 1.

Second, use the .text() method to get the text content of an element.

And you don't need to call find() repeatedly, just put all the selectors together.

DEMO

Upvotes: 2

Related Questions