parent
UK [ˈpeərənt] US [ˈperənt]
n.Father (or mother); ancestor; root, origin; protector
jquery parent() method syntax
Function: parent() Gets the parent element of each element in the current matching element set. Filtering with a selector is optional.
Syntax: .parent(selector)
Parameters:
Parameter | Description |
selector | String value, containing the selector expression used to match elements. |
Description: If given a jQuery object that represents a collection of DOM elements, the .parent() method allows us to search for these elements in the DOM tree. parent element and constructs a new jQuery object with the matching element. The .parents() method is similar to the .parent() method, except that the latter traverses a single level up the DOM tree. This method accepts an optional selector expression of the same type as the argument we passed into the $() function. If this selector is applied, elements will be filtered by testing whether they match the selector.
jquery parent() method example
<!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <div><p>Hello</p></div> <div class="selected"><p>Hello Again</p></div> <script> $("p").parent(".selected").css("background", "yellow"); </script> </body> </html>
Click the "Run instance" button to view the online instance