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

Traversing Down the DOM Tree

Two useful jQuery methods for traversing down the DOM tree are:

  • children()
  • find()

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(){
                    console.log($(".ul1").children().length);
                    console.log($(".div2").find(".ul1").children().length);
                    $(".div2").find(".ul1").children().css("background-color","blue");
                });
            });    
                
        </script>
        <div width="500" height="300" style="background-color: orange;">
            hello
        <div class="div1">
            <ul class="ul1">
                <li>1</li>
                <li>2</li>
            </ul>
            <button id="btn">click here for child</button>
        </div>
       </div>
        <div class="div2">
            <ul class="ul1">
                <li>1</li>
                <li>2</li>
            </ul>
            <button id="btn">click here for child</button>
        </div>
    </body>
</html>
Next
Next Topics
Next lessons of current book.
JQuery of JQuery
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