Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector anchor inside div

I have the following HTML code:

<div id="mycontainer">
   <p> title </p>
   <ul>
   <li><span>**</span><a href="...">KEY</a></li>
   </ul>
   <ul>
   ...
   </ul>
</div>

How would I get the KEY value? In other words, from this div with id = "mycontainer", how would I go to get from the first ul, the content of the element?

like image 627
Hommer Smith Avatar asked Nov 20 '12 17:11

Hommer Smith


2 Answers

$("#mycontainer ul:first a").text();

here, have a fiddle: http://jsfiddle.net/8tvTt/

like image 197
Adriano Carneiro Avatar answered Oct 11 '22 16:10

Adriano Carneiro


Something like this will achieve what you're after:

$("#mycontainer ul:first a").text();

like image 39
dsgriffin Avatar answered Oct 11 '22 15:10

dsgriffin