Skip to content
Related Articles

Related Articles

jQuery Traversing Complete Reference

Improve Article
Save Article
  • Last Updated : 28 Nov, 2022
Improve Article
Save Article

In jQuery, traversing means moving through or over the HTML elements to find, filter, or select a particular or entire element.

Syntax:

$(selector).method()

Example: This example illustrates the offsetParent() method in jQuery.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>The offsetParent Method</title>
    </script>
  
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function(){
            $("button").click(function(){
                $("p").offsetParent().css("background-color", "green");
            });
        });
    </script>
    <style>
        #d1 {
            border:1px solid black;
            width:70%;
            position:absolute;
            left:10px;
            top:50px
        }
        #d2 {
            border:1px solid black;
            margin:50px;
            background-color:lightblue;
            text-align:center;
        }
        p {
            padding-left: 80px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <button>Submit</button>
    <div id="d1">
        <div id="d2">
            <!-- click on this paragraph -->
  
            <p>Welcome to GeeksforGeeks!</p>
  
        </div>
    </div>
</body>
</html>


Output:

 

Complete Reference:

jQuery Traversing Complete List:

Description

jQuery add() Method This is used to add elements to the existing group of elements.
jQuery addBack() Method The addBack() is an inbuilt method in jQuery that adds the previous set of elements to the current set.
jQuery children() Method This is used to find all the children’s elements related to that selected element. 
jQuery closest() Method That returns the first ancestor of the selected element in the DOM tree
jQuery contents() Method That returns all the direct children, including text and comment nodes for the selected element.
jQuery each() Method Each () Method in jQuery is used to specify the function to run for each matched element.
jQuery eq() Method This is used to locate the selected elements directly and returns an element with a specific index. 
jQuery filter() Method The filter() method is used to filter out all the elements that do not match the selected criteria and those matches will be returned.
jQuery find() Method The find() is an inbuilt method in jQuery that is used to find all the descendant elements of the selected element. 
jQuery first() Method The first() is an inbuilt function in jQuery that is used to select the first element from the specified elements. 
jQuery has() Method The has() is an inbuilt method in jQuery that is used to find all the elements inside the specified list of elements.
jQuery is() Method The is() method is used to check if one of the selected elements matches the selectorElement.
jQuery last() Method The last() function is an inbuilt function in jQuery that is used to find the last element of the specified elements.
jQuery map() Method This map() Method in jQuery is used to translate all items in an array or object to a new array of items.
jQuery next() & nextAll() Method The next() is an inbuilt function in jQuery that is used to return the next sibling of the selected element.
jQuery nextUntil() Method This is used to find all sibling elements between two given elements.
jQuery not() method Method This function will return all the element which is not matched with the selected element with the particular “id” or “class”.
jQuery offsetParent() Method This is used to find the first positioned parent element in the DOM tree.
jQuery parent() & parents() Method The parent() is an inbuilt method in jQuery that is used to find the parent element related to the selected element.
jQuery parentsUntil() Method This is used to find all the ancestor elements between two given elements in a DOM tree.
jQuery prev() & prevAll() Method This is used to return the previous sibling element of the selected element. 
jQuery prevUntil() Method This is used to find all the previous sibling elements between two given elements. 
jQuery siblings() Method The siblings are those having the same parent element in DOM Tree. 
jQuery slice() Method This is used to select a subset of elements based on its index.

 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!