Knowledge Walls
Ammu
Hyderabad, Andhra Pradesh, India
Passcode:
JQuery Traversing - Siblings in JQuery of JQuery
1085 Views

Traversing Sideways in The DOM Tree

There are many useful jQuery methods for traversing sideways in the DOM tree:

  • siblings()
  • next()
  • nextAll()
  • nextUntil()
  • prev()
  • prevAll()
  • prevUntil()
example
<!DOCTYPE html>
    <html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <title>internal</title>
        <script   src="https://code.jquery.com/jquery-3.4.1.min.js"   integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="   crossorigin="anonymous"></script>
    </head>
    <body>
        <script>
            $(document).ready(function(){
                $("#btn").click(function(){
                  $(".class1").find(".students").siblings().css("background-color","blue");
                  $(".class1"). find(".students").next().css("color","red");
                $(".class1").find(".teachers").nextAll().css("font-size","30px");
                    $(".class1").find(".office").prev().css("font-weight","bold");
                    $(".class1").find(".office").prevAll().css("text-decoration","underline");
                    $(".class1").find(".office").parentsUntil().css("color","yellow");
                });
            });    
                
        </script>
        <div width="500" height="300" style="background-color: orange;">
            <div class="class1">
            <ul class="teachers">
                <li>Sarathy</li>
                <li>Partha</li>
            </ul>
            <ul class="students">
                <li>Siva</li>
                <li>Ram</li>
            </ul>
            <ul class="office">
                <li>Kala</li>
                <li>JOhn</li>
            </ul>
            </div>
        </div>
        <button id="btn">click here</button>
    </body>
</html>
Next Topics
Next lessons of current book.
JQuery of JQuery
Previous Topics
Previous lessons of current book.
JQuery of JQuery
Best Lessons of "JQuery"
Top lessons which are viewed more times.
JQuery of JQuery
JQuery of JQuery
JQuery of JQuery
JQuery of JQuery
JQuery of JQuery
JQuery of JQuery
JQuery of JQuery
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details