Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check next sibling of an element in jQuery?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 300
    Comment on it

    Hello friends,

    Today we learn how to check next sibling of an element using jQuery. In jQuery, next() method is used to match the immediate sibling of an element.

    Syntax:

    .next( [selector ] )

    selector is the optional parameter which is an expression to match the element.

    Let's take an example to understand the .next() method. Suppose we have an element span whose next we want to display a text. For this you need to write the code as follow:

    <!DOCTYPE html>
    <html>
    <head>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
    	$(".test1").next().text('This is the sibling ');
    });
    </script>
    </head>
    <body class="siblings">
      <span class="test1">span</span>
      <span></span>
    </body>
    </html>
    

     

 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: