jQuery children () method
Examples
Back <ul> direct child elements:
$("ul").children().css({"color":"red","border":"2px solid red"});
});
result:
- ul (parent)
- li (child) span (grandchild)
try it"
Definition and Usage
children () method returns the selected element all the direct child elements.
DOM tree: This method is only a single level traverse down the DOM tree. For traversing down several levels (return descendants of nodes or other descendants), use the find () method.
Tip: To traverse the DOM tree upwards along a single level, or through all paths until the document root element upward (return parent or other ancestor), use parent () or parents () method.
Note: This method does not return a text node. To return all child nodes that contain text nodes, use the contents () method.
grammar
参数 | 描述 |
---|---|
filter | 可选。规定缩小搜索子元素范围的选择器表达式。 |
More examples
Back <ul> All immediate child elements
How to Return <ul> element of all direct child elements.
Narrow your search
How to use the filter parameter to return <ul> direct child element with class name of "1" for all <li> elements.
Back <div> direct child elements of all <p> elements
How to select the <div> elements direct child of all <p> elements.
Presentation by descendants of the tag name of the element
Demo <div> element descendants.