How to select specific ancestors of an element in jQuery ? Last Updated : 31 May, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will select specific ancestor elements of an element in jQuery. To select the specific ancestor elements of an element, we use the parents() method. This method is used to find the parent elements related to the selected element. This parent () method traverse all the levels up the selected element and returns all elements. Syntax: $(selector).parents() Here selector is the selected element that all parents need to find. It returns all the parents of the selected element. Example: In this example, we are using the above-explained method. HTML <!DOCTYpe html> <html> <head> <title> How to select specific ancestor elements of an element in jQuery? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script> $(document).ready(function () { $("li").parents("ul").css({ color: "green", border: "2px solid green" }); }); </script> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> How to select specific ancestor elements of an element in jQuery? </h3> <p>GeeksforGeeks Subjects List-</p> <ul> <li>HTML</li> <li>CSS</li> <li>JavaScript</li> <li>PHP</li> </ul> </body> </html> Output: Comment More infoAdvertise with us Next Article How to select specific ancestors of an element in jQuery ? V vkash8574 Follow Improve Article Tags : Web Technologies JQuery HTML-Tags CSS-Properties jQuery-Selectors jQuery-Methods HTML-Questions CSS-Questions jQuery-Questions +5 More Similar Reads How to select all ancestors of an element in jQuery ? In this article, we will select all the ancestor elements of an element in jQuery. To select all ancestor elements of an element, the parents() method is used. This method is used to find all the parent elements related to the selected element. This method traverses all the levels up the selected el 1 min read How to check an element contains specific class in jQuery ? In this article, we will see how to check if an element contains a specific class using jQuery. The Jquery function called hasClass() function will be used, which will return a boolean result if the particular element contains any specific class. Note that we can check for multiple classes available 3 min read How to select all sibling elements of an element using jQuery ? In this article, we will discuss how to select all sibling elements of an element using jQuery. To select all sibling elements of an element, we will use the siblings() method. The siblings() method is used to find all sibling elements of the selected element. The siblings are those having the same 2 min read How to select direct parent element of an element in jQuery ? In this article, we will select the direct parent element of an element using jQuery. To select the direct parent element, the parent() method is used. This method finds the parent element related to the selected element. This parent() method traverses a single level up the selected element and retu 1 min read How to select elements by attribute in jQuery ? jQuery is a lightweight JavaScript library. In the vanilla JavaScript language, the getElementById method is used to select an element. However, jQuery provides a much lighter alternative for the same purpose. The 'jQuery Selector' allows the user to manipulate HTML elements and the data inside it(D 2 min read Like