jQuery中的siblings

简介:


所谓siblings,英文翻译就是兄弟节点。那么故名思意,就是拿到某元素的兄弟节点(不包括自己)。


<html>
<head>
  <script type="text/javascript" src="/jquery/jquery.js"></script>
</head>

<body>
<ul>
    <li>li1</li>
    <li>li2</li>
    <li id="li3">li3</li>
    <li>li4</li>
    <li>li5</li>
</ul>

<script>
     $("#li3").siblings("li").css("backgroundColor", "yellow");
</script>

</body>
</html>

 

 

我们还知道,
$("#li3").siblings("li").css("backgroundColor", "yellow")

在本例中可以写成

$("#li3").siblings().css("backgroundColor", "yellow")

默认拿和它自己相同的兄弟元素。

 

 


目录
相关文章
|
12月前
|
JavaScript
jQuery 遍历 - 同胞(siblings)
jQuery 遍历 - 同胞(siblings)
97 6
|
JavaScript
jQuery 遍历 - 同胞(siblings)
jQuery 遍历 - 同胞(siblings)
57 2
|
JavaScript
jQuery 遍历 - siblings() 方法应用
jQuery 遍历 - siblings() 方法应用
113 0
|
JavaScript
jQuery的addClass、siblings、removeClass、each、html、eq、show/hide用法
jQuery的addClass、siblings、removeClass、each、html、eq、show/hide用法
jQuery的addClass、siblings、removeClass、each、html、eq、show/hide用法
|
JavaScript 前端开发
jQuery 遍历|同胞(siblings)
同胞拥有相同的父元素。 通过 jQuery,您能够在 DOM 树中遍历元素的同胞元素。 在 DOM 树中水平遍历 有许多有用的方法让我们在 DOM 树进行水平遍历: 这些方法相当于是集合的过滤条件 siblings() next() nextAll() nextUntil() prev() prevAll() prevUntil() siblings() 方法 siblings() 方法返回被选元素的所有同胞元素。
1083 0
|
6月前
|
JavaScript 前端开发
百叶窗效果的jQuery幻灯片插件
百叶窗效果的jQuery幻灯片插件
|
6月前
|
JavaScript
jquery无限循环内容滑块插件
jquery无限循环内容滑块插件
|
6月前
|
JavaScript
简单轻量级的jquery图表插件
简单轻量级的jquery图表插件
|
6月前
|
JavaScript
jQuery响应式内容选项卡插件
jQuery响应式内容选项卡插件