Home JQuery How to find the id of the first anchor html element within the first element of an unordered list using JQuery?
 
 
 

How to find the id of the first anchor html element within the first element of an unordered list using JQuery?

PDF Print E-mail

Question: How to find the id of the first anchor html element within the first element of an unordered list using JQuery? With getting the id I mean getting the attribute id's value for the first element within the first element of the unordered list tag.

 

Answer:

We can obtain this by using the :first Selector from JQuery. Read more about the selector here

Example:

HTML

 
<ul class="custom_class">
    <li><a href="test1.html" id="1" name="link1" /></li>
    <li><a href="test2.html" id="2" name="link2" /></li>
    <li><a href="test3.html" id="3" name="link3" /></li>
    <li><a href="test4.html" id="4" name="link4" /></li>
    <li><a href="test5.html" id="5" name="link5" /></li>
</ul>
 


JQuery

 
        var id = $('.custom_class li a:first').attr('id');
 
 

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!