By submitting your email you agree to our Privacy Policy. Syntax: How to increase the width of a div by specified pixels once it is clicked using jQuery ? This function locates the specified elements parent element. This method is not used to traverse through the text nodes. JavaScript get child elements by className, How to get a ancestor node with a specific tag name, Select a class which is part name and part variable, document.getElementsByName("") equivalent in YUI3.0, Get parent element of nested child by class or name. #javascript The .closest and .find selectors are complements of each other and used together are the best way to get to the corresponding element of where the click (or any event) occurred. Using jQuery to see if a div has a child with a certain class Ask Question Asked 11 years, 2 months ago Modified 8 months ago Viewed 220k times 142 I have a div #popup that is dynamically filled with several paragraphs with the class .filled-text. Share Improve this answer Follow edited Sep 8, 2015 at 21:17 TylerH 20.7k 65 73 98 Example It takes the selector as a parameter and changes the children element with the specified name. Then, following the parentheses, put a dot after the technique we want to employ. two paragraphs and one div. 5 Answers Sorted by: 179 In this case you need to go up to the <tr> then use .next (), like this: $ (obj).closest ('tr').next ().find ('.class'); Or if there may be rows in-between without the .class inside, you can use .nextAll (), like this: $ (obj).closest ('tr').nextAll (':has (.class):first').find ('.class'); Share Improve this answer Follow The parent class is used to apply a specific style to a group of HTML elements. Since we do not supply a selector expression, all of the siblings are part of the object. What is the difference between 1206 and 0612 (reversed) SMD resistors? CSS ID properties will take precedence over CSS Class properties. Connect and share knowledge within a single location that is structured and easy to search. jQuery parent() & parents() Method - GeeksforGeeks But you have to add the dot next to the class name querySelector('.sonClassName'), otherwise it will handle it as sonClassName is a tag name not a class name. First we spread the elements of the NodeList to turn it into an Array so we can make use of the find() method. First, with the help of the class name, we can determine the parent class of an element in an HTML. from former US Fed. See jQuery License for more information. (with no additional restrictions), Single Predicate Check Constraint Gives Constant Scan but Two Predicate Constraint does not, Can be followed by letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_"). Unpacking "If they have a question for the lawyers, they've got to go outside and the grand jurors can ask questions." How to get the classes of an element's children in JS? The on() method is used to choose an event handler for a group of components. What is the least number of concerts needed to be scheduled in order that each musician may listen, as part of the audience, to every other musician? .siblings() | jQuery API Documentation How to change background color of paragraph on double click using jQuery ? Share your suggestions to enhance the article. How to test whether an element has a specific class? jQuery select child element by class with unknown path .closest() | jQuery API Documentation From the documentation (paraphrased): The .closest selector traverses up the DOM to find the parent that matches the conditions. Convert getted result of InnerHTML text to an element, Javascript: retrieve hidden field value inside element with ID, select elements by class that have a specific child element with javascript, Multiple event handlers only firing on first element, not the target, How to use document.querySelector() to find elements with a specific class name that are within a div with a specific ID,