Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is .siblings() method in jQuery?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 250
    Comment on it

    Hello Readers,

    If we want to fetch or return the all sibling elements of the selected or matched elements then we use the .siblings() method in jQuery.

    It is the elements that belong to the same parent.

    Syntax :

    selector.siblings( [selector] )
    

    Parameters :

    selector - selector is a optional parameter which is used to filter the sibling elements.

    Below is the Code Example of siblings method :

    <html>
    
       <head>
          <title>The jQuery Example</title>
          <script type = "text/javascript" 
             src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    
          <script type = "text/javascript" language = "javascript">
             $(document).ready(function(){
                $("p").siblings('.selected').addClass("hilight");
             });
          </script>
    
          <style>
             .hilight { background:yellow; }
          </style>
       </head>
    
       <body>
    
          <div><span>Hello</span></div>
          <p class = "selected">Hello Again</p>
          <p>And Again</p>
    
       </body>
    
    </html>
    

    In the above Code, we use the optional parameter class (.selected) and addClass (hilight) on it.

 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: