Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add class or other attribute on first and last child of a element

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 358
    Comment on it

    How to add class or other attribute on first and last child of a element

    here is ul have five li and i want to add class on first and last li

    <ul id="parentElement">
    <li>First</li>
    <li>Second</li>
    <li>Third</li>
    <li>Forth</li>
    <li>Fifth</li>
    </ul>
    
    
    
    $("#parentElement> :first-child").addClass("firstClass");
    $("#parentElement> :last-child").addClass("lastClass");
    

 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: