jquery遍历函数siblings()用法实例
本文实例讲述了jquery遍历函数siblings()用法。分享给大家供大家参考,具体如下:
siblings([expr])
得到所有匹配元素集合中各个元素的所有兄弟元素集合。返回匹配元素集合
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<scriptsrc="jquery.js"></script>
<script>
$(document).ready(function(){
varlen=$(".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:10px20px;font-size:16px;padding:5px;
font-weight:bolder;}
.hilite{background:yellow;}
</style>
</head>
<body>
<ul>
<li>One</li>
<li>Two</li>
<liclass="hilite">Three</li>
<li>Four</li>
</ul>
<ul>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
</ul>
<ul>
<li>Eight</li>
<liclass="hilite">Nine</li>
<li>Ten</li>
<liclass="hilite">Eleven</li>
</ul>
<p>Uniquesiblings:<b></b></p>
</body>
</html>
$(".hilite").siblings()
将得到包含特殊样式‘hilite'元素的所有兄弟元素集合。以下是匹配元素集合
<li>One</li> <li>Two</li> <li>Four</li> <li>Eight</li> <liclass="hilite">Nine</li> <li>Ten</li> <liclass="hilite">Eleven</li>
希望本文所述对大家jQuery程序设计有所帮助。