Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to select first child of an element

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 219
    Comment on it

    In some cases we need to add or remove an attribute to an element and we have only his parent ID then we can get the child element by using parent ID. For example I have a UL element which have many <li> and each <li> has an anchor tag.

    <ul id="parentUL">
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
    <li><a></a></li>
    </ul>
    

    I want to add a class on very first anchor tag and i have only parent ID. For this i can use this code

    $( "#parentUL a" ).first().addClass('active');
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: