What is the parent syntax in jquery
This article mainly explains "what is the parent syntax in jquery". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what is the parent syntax in jquery" together!
In jquery, parent is a built-in traversal method that traverses a single level up the DOM tree and returns the immediate parent of the selected element, syntax "specify element object.parent(filter)"; this method accepts an optional parameter "filter" that filters elements and narrows the search for parent elements.
This tutorial operates on Windows 7, jquery version 1.10.2, Dell G3 PC.
In jquery, parent is a built-in traversal method that returns the immediate parent of the selected element.
The parent() method traverses only a single level up the DOM tree.
Syntax format:
Specifies the element object.parent(filter) parameter description filter
Optional. Specifies a selector expression that narrows the search for parent elements.
This parameter is used to filter elements and narrow the search for parent elements.
Example 1: The parent() method returns the direct parent element (filter omitted)
$(document).ready(function() { $("span").parent().css({ "color": "red", "border": "2px solid red" }); }); .ancestors * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } body (great-great grandfather node) div (great-grandfather node) ul (grandfather node) li (direct parent) span li (direct parent) span
Example 2: The parent() method returns the direct parent element (filter not omitted)
Following the example above, modify the jq code:
$(document).ready(function() { $("span").parent("li.1").css({ "color": "red", "border": "2px solid red" }); });
Thank you for reading, the above is the content of "what is the parent syntax in jquery", after learning this article, I believe everyone has a deeper understanding of what the parent syntax in jquery is, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!