这篇文章主要介绍了jquery遍历函数siblings()用法,结合实例形式较为详细的分析了jquery的siblings函数用于元素遍历的相关技巧,需要的朋友可以参考下
本文实例讲述了jquery遍历函数siblings()用法。分享给大家供大家参考,具体如下:
siblings([expr])
得到所有匹配元素集合中各个元素的所有兄弟元素集合。返回匹配元素集合
<!doctype html public "-//w3c//dtd html 4.01 transitional//en"
"http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
var len = $(".hilite").siblings().css("color", "red").length;
$("b").text(len);
});
</script>
<style>
ul { float:left; margin:5px; font-size:16px; font-weight:bold; }
p { color:blue; margin:10px 20px; font-size:16px; padding:5px;
font-weight:bolder; }
.hilite { background:yellow; }
</style>
</head>
<body>
<ul>
<li>one</li>
<li>two</li>
<li class="hilite">three</li>
<li>four</li>
</ul>
<ul>
<li>five</li>
<li>six</li>
<li>seven</li>
</ul>
<ul>
<li>eight</li>
<li class="hilite">nine</li>
<li>ten</li>
<li class="hilite">eleven</li>
</ul>
<p>unique siblings: <b></b></p>
</body>
</html>
复制代码 代码如下:
$(".hilite").siblings()
将得到包含特殊样式‘hilite'元素的所有兄弟元素集合。以下是匹配元素集合
<li>one</li>
<li>two</li>
<li>four</li>
<li>eight</li>
<li class="hilite">nine</li>
<li>ten</li>
<li class="hilite">eleven</li>
以上就是有关jquery中的遍历函数siblings()其用法详解的详细内容。