jquery siblings() is used to obtain all sibling elements of the selected element. It will traverse forward and backward along the sibling elements of the DOM element and return all child elements that share the same parent element (the selected element). Except for elements); the syntax is "element object.siblings(filter)", and its parameters can be omitted to narrow the search scope.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The jquery siblings() method is used to obtain all sibling elements of the selected element.
Sibling elements are elements that share the same parent element.
siblings() method will traverse forward and backward along the sibling elements of the DOM element, returning all child elements that share the same parent element (except the selected element).
Grammar format:
$(selector).siblings(filter)
Parameters | Description |
---|---|
filter | Optional. Specifies a selector expression that narrows the search for sibling elements. |
Example 1:Return all sibling elements of each
ul (父节点)
- li (类名为"star"的上一个兄弟节点)
- li (类名为"star"的上一个兄弟节点)
- li (兄弟节点)
- li (类名为"star"的下一个兄弟节点)
- li (类名为"star"的下一个兄弟节点)
在这个例子中,我们选择类名称为“star”的li元素的所有兄弟元素。
Example 2:Narrow the search (use two parameters to filter the search for sibling elements)
ul(父节点)
- li (类名为"star"的上一个兄弟节点)
- li(类名为"star"的上一个兄弟节点)
- li (兄弟节点)
- li(类名为"star"的下一个兄弟节点)
- li (类名为"star"的下一个兄弟节点)
在这个例子中,我们缩小搜索结果只返回在类名为“star”和“stop”的li元素之间类名为“1”的兄弟元素。
[Recommended learning:jQuery video tutorial,web front-end video]
The above is the detailed content of What is the usage of jquery siblings(). For more information, please follow other related articles on the PHP Chinese website!