jQuery prevAll () method
Examples
Returning each <li> element with the class name "start" before all the sibling elements:
$("li.start").prevAll().css({"color":"red","border":"2px solid red"});
});
result:
- ul (parent)
- li (sibling)
- li (sibling)
- li (sibling)
- li (sibling with class name "start")
- li (sibling)
- li (sibling)
try it"
Definition and Usage
prevAll () method returns all sibling elements before the selected element.
Sibling elements are elements that share the same parent element.
DOM tree: This method traverses back along the sibling elements of the DOM element.
Related methods:
- the PREV () - Returns selected elements of the previous sibling element
- prevUntil () - Returns all elements of the two siblings to each element before the given parameters
grammar
参数 | 描述 |
---|---|
filter | 可选。规定缩小搜索元素之前的同级元素范围的选择器表达式。 注意:如需返回多个同级元素,请使用逗号分隔每个表达式。 |
More examples
Narrow your search
How-to-peer search filter element before the element.
Return more than one sibling elements
How to use the filter parameter returns all sibling elements with a class name of "1", "2" and "3" <h2> element.
Select all sibling elements <p> element before
How to select all siblings <p> element before.
All peer <p> element select <div> before
How to select all of the peer <p> element for each <div> element before.