jQuery prevAll() 方法
jQuery 教程
· 2019-03-28 11:18:45
实例
返回带有类名 "start" 的每个 <li> 元素之前的所有同级元素:
$(document).ready(function(){
$("li.start").prevAll().css({"color":"red","border":"2px solid red"});
});
结果:
- ul (parent)
- li (sibling)
- li (sibling)
- li (sibling)
- li (sibling with class name "start")
- li (sibling)
- li (sibling)
定义和用法
prevAll() 方法返回被选元素之前的所有同级元素。
同级元素是共享相同父元素的元素。
DOM 树:该方法沿着 DOM 元素的同级元素向后遍历。
相关方法:
- prev() - 返回被选元素的前一个同级元素
- prevUntil() - 返回两个给定参数之间的每个元素之前的所有同级元素
语法
$(selector).prevAll(filter)
| 参数 | 描述 |
|---|---|
| filter | 可选。规定缩小搜索元素之前的同级元素范围的选择器表达式。 注意:如需返回多个同级元素,请使用逗号分隔每个表达式。 |
点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html
The Nature of Code
Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95
How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!