什么是遍历?

jQuery 遍历,意为"移动",用于根据其相对于其他元素的关系来"查找"(或选取)HTML 元素。以某项选择开始,并沿着这个选择移动,直到抵达您期望的元素为止。

下图展示了一个家族树。通过 jQuery 遍历,您能够从被选(当前的)元素开始,轻松地在家族树中向上移动(祖先),向下移动(子孙),水平移动(同胞)。这种移动被称为对 DOM 进行遍历。

图示解析:

  • <div> 元素是 <ul> 的父元素,同时是其中所有内容的祖先。
  • <ul> 元素是 <li> 元素的父元素,同时是 <div> 的子元素
  • 左边的 <li> 元素是 <span> 的父元素,<ul> 的子元素,同时是 <div> 的后代。
  • <span> 元素是 <li> 的子元素,同时是 <ul> 和 <div> 的后代。
  • 两个 <li> 元素是同胞(拥有相同的父元素)。
  • 右边的 <li> 元素是 <b> 的父元素,<ul> 的子元素,同时是 <div> 的后代。
  • <b> 元素是右边的 <li> 的子元素,同时是 <ul> 和 <div> 的后代。
祖先是父、祖父、曾祖父等等。后代是子、孙、曾孙等等。同胞拥有相同的父。

---------------jQuery 遍历 - 祖先

祖先是父、祖父或曾祖父等等。

通过 jQuery,您能够向上遍历 DOM 树,以查找元素的祖先。

向上遍历 DOM 树

这些 jQuery 方法很有用,它们用于向上遍历 DOM 树:

  • parent()
  • parents()
  • parentsUntil()

    jQuery parent() 方法

    parent() 方法返回被选元素的直接父元素。

    该方法只会向上一级对 DOM 树进行遍历。

    下面的例子返回每个 <span> 元素的的直接父元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.ancestors *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("span").parent().css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body> <div class="ancestors">
<div style="width:500px;">div (曾祖父元素)
<ul>ul (祖父元素)
<li>li (父元素)
<span>span</span>
</li>
</ul>
</div> <div style="width:500px;">div (祖父元素)
<p>p (父元素)
<span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DBpASCYtAAQTFoACCYtAASTFgCCSQsAwaQFgGDSAkAwaQEgmLQAEExaAAiWPS0A7JO0ABAsS1oAYAlpASCYtAAQTFoACCYtAASTFgCCSQsAwaQFgGDSAkAwaQEgmLQAEExaAAgmLQAEkxYAgv0DnqO2RbGabewAAAAASUVORK5CYII=" alt="" />

jQuery parents() 方法

parents() 方法返回被选元素的所有祖先元素,它一路向上直到文档的根元素 (<html>)。

下面的例子返回所有 <span> 元素的所有祖先:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.ancestors *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("span").parents().css({"color":"red","border":"2px solid red"});
});
</script>
</head> <body class="ancestors">body (曾曾祖父元素)
<div style="width:500px;">div (曾祖父元素)
<ul>ul (祖父元素)
<li>li (父元素)
<span>span</span>
</li>
</ul>
</div>
</body> </html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmcAAAFLCAIAAAAcVryWAAAVqUlEQVR4nO3dTZajxhIGUO2IFbEg7Ya9mIknnnjWUy8gPZCE+FdWCVIBuvfkwF2gEOpTL77OTNC7JAAgz+XTFwAAhyE1ASCX1ASAXFITAHJJTQDIJTUBIJfUBIBcUhMAcq2m5uViGIZhGF86pKZhGIZh5I5fpiYAfBWpCQC5pCYA5JKaAJBLagJALqkJALmkJgDkkpoAkGuX1Pz486eGYRiG8c6QmoZhGIaROz6QmgBwOFITAHJJTQDIJTUZqy/p2n76IgBC+mRqttd02bBBt6m6pOq6XbUqjS5tLU6yz79W6VJvdJH7kJoAS6Tm80qa4Q+vVbr0grC+pLoZv/A357ep6n3qazVzd9bSG9W9i6wnF3zT1K/v/nr+LTW5N4zVzf1kgQp8M6k5iLHbJeWM351/f8Pr8zqv1Tgjpz/pfn6pU3ur06S63ivDVuaas/+8APgeUjM19XPJtL1Olk/bVE1you6n5k/On8pMzdFE9nm1r2bAL+UEf/8trtV2y+AARxMiNfurlKMIGKw3TmKjf7TppeY0YxYTerheek/B/g97Kdhe72XHqZl5/mg5tEptXmrORmb/c20bY+v7mt2HAvhCn0/NfpjVw2gcpcUtXJuFP9a9HbtpRi7dgzPKgP7c8R4ejxTsT0ln55o55/ev5xnwq3O7299JPTfDu1988/jgbarylou7f6DUPzw/pfG/MwC+yudTczCvalP1+MnM7LC/BttMXtuFx+jMYdmRfralvOXKftL/bl+z/6brc81nqDczM7znYunC0WfluRPGfw+TzdelWezLG6MAzurzqTmatdTLq6ypN2W8dflB6x4mZVM/X76yqFh+l2505T+6G2jwd9XMLGgv1llJzeXbaJv0uPloUtnWJvCdIqbmLRdn11S7KO2H4t1oftl7TGKly88eerFuObmq/PO7jdjqEWn5qTlKvpfRNVgWfjXX7GoOLriZX9aWmsDXipiam8w1n6VW9+GWUnPt0Yu51Mw6vxncOnRLxx89r9nUg43btVXS0adeT83Hhuj8U6Rz/3aRmsB3+nxqTvcm+1uG033NpV3P6T7cbT7arN7zOdrXvNlvrtl9il+s0D6P1mvJen+T0aduJn98/O3NfivCIBQnM077msDX+nxqXoY3Z/Yb9PottfX0taN2f5t9robQ7JbnXnPN3lX9MjVnP+acepp8k9RcepNuRtv/yfMDuocW+GKfT81r03teYnYjM2eSV6V27lsORk+nzJjLgJipefssizcYj84c/VNgmJrTXeH+nLtLzdmVWM9rAt/sk6lZQM5XpU+zocQKbcazlaNHUZf+STGdXs+m2mgDtUvc+wptldr2/qouttt2ENVLf10A3+PUqZm5ljg5reRc8+WFrcwpn29xeX7dwY92HMfP50wCu7uM6+P7b1/M3QFO7cypmf//yeVLybP8PJUBTuacqflcddz3fQD4LudMTQDYg9QEgFxSEwBySU0AyCU1ASCX1ASAXFITAHJJTQDIJTUBIJfUBIBcUhMAcklNAMglNQEgl9QEgFxSEwBySU0AyHWM1Ly9xDAMw/jOEcf69SwflZqGYRhGqRHH+vUsH/1EagLwbaL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0tNAOKK1v+lJgBxRev/UhOAuKL1f6kJQFzR+v+RUtMwDMP4zhHH+vUsH5WahmEYRqkRx/r1LB8tm5oAEIHUBIBcUhMAcklNAMglNQEgl9QEgFxSEwBySU0AyCU1ASCX1ASAXFITAHJJTQDIJTUBIJfUBIBcUhMAcn0sNQ3DMAzjoENqGoZhGEbuKJqaAHBKUhMAcklNAMglNQEgl9QEgFxSEwBySU0AyCU1ASDXW6lpGIZhGF84pKZhGIZh5I4fpyYA0CM1ASCX1ASAXFITAHJJTQDIJTUBIJfUBIBcUhMAcklNAMglNQEgl9QEgFxSEwBy/Q9OWOhPk9OX8AAAAABJRU5ErkJggg==" alt="" />

jQuery parentsUntil() 方法

parentsUntil() 方法返回介于两个给定元素之间的所有祖先元素。

下面的例子返回介于 <span> 与 <div> 元素之间的所有祖先元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.ancestors *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("span").parentsUntil("div").css({"color":"red","border":"2px solid red"});
});
</script>
</head> <body class="ancestors"> body (曾曾祖父元素)
<div style="width:500px;">div (曾祖父元素)
<ul>ul (祖父元素)
<li>li (父元素)
<span>span</span>
</li>
</ul>
</div>
</body> </html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjUAAAEtCAIAAAB/GgakAAASlklEQVR4nO3dPXarPKOAUc/II2JAng1zOTRp3KRzmwFwCvwjQCAIjizsvRfFe2IiE+5aej4B9j20AFCew6sPAAAi9AmAEukTACXSJwBKpE8AlEifACiRPgFQIn0CoET6BECJ9AmAEukTACXSJwBKpE8AlEifACiRPgFQIn0CoET6BECJ9AmAEukTACXSJwBKpE8AlEifACiRPr2DujocT82rjwLgmVb2qTkdD0+cCp87XHM6DseanbiX7t+cjodDVT/nIP+EPgHvZ7d9ikVjMFxdJ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z5lGQFgXwqYOfUpywgA+1LAzKlPWUYA2JcCZk59yjICwL4UMHPqU5YRAPalgJlTn7KMALAvBcyc+pRlBIB9KWDm1KcsIwDsSwEzpz5lGQFgXwqYOfUpywgA+1LAzKlPWUYA2JcCZk59yjICwL4UMHPqU5YRAPalgJlTn7KMALAvBcyc+pRlBIB9KWDm1KcsIwDsSwEzpz4tHsFms9k+bXvp3KtPi0ew2Wy2T9teOvfqEwB/QJ/S9AkgP31K0yeA/PQpTZ8A8tOnNH0CyE+f0vQJID99StMngPz0KU2fAPLTpzR9AshPn9L0CSA/fUrTJ4D89ClNnwDy06c0fQLIT5/S9AkgP31K0yeA/PQpTZ8A8tOnNH0CyE+f0vQJID99StMngPz0KU2fAPLTp7TuHNlsNpst//ba+b+LwPYhovTJZrPZdry9dv7vIrB9iKhnHR8A+6JPAJRInwAokT4BUCJ9AqBE+gRAifQJgBLpEwAl0icASqRPAJRInwAokT4BUCJ9AqBE+gRAifQJgBLpEwAl0icASqRPAJRInwAokT4BUKJ99AmAz7S9I/oEwPNt78hf9QkAttAnAEqkTwCUSJ8AKJE+AVAifQKgRPoEQIn0CYAS6RMAJdInAEr0H29gS8e1gf/tAAAAAElFTkSuQmCC" alt="" />

---------------jQuery 遍历 - 后代-----------------


后代是子、孙、曾孙等等。

通过 jQuery,您能够向下遍历 DOM 树,以查找元素的后代。

向下遍历 DOM 树

下面是两个用于向下遍历 DOM 树的 jQuery 方法:

  • children()
  • find()

jQuery children() 方法

children() 方法返回被选元素的所有直接子元素。

该方法只会向下一级对 DOM 树进行遍历。

下面的例子返回每个 <div> 元素的所有直接子元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.descendants *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("div").children().css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body> <div class="descendants" style="width:500px;">div (当前元素)
<p>p (儿子元素)
<span>span (孙子元素)</span>
</p>
<p>p (儿子元素)
<span>span (孙子元素)</span>
</p>
</div> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhYAAAEZCAIAAABEm/vMAAARu0lEQVR4nO3dQZKiMBgGUG/kiTyQt/Eu46Y3bty59QDMQo2QBAQUTfS9yqLbJkD3VP0fSYBZNQAwy+rTJwBArUQIADOJEABmEiEAzCRCAJhJhAAwkwgBYCYRAsBMIgSAmUQIADOJEABmEiEAzCRCAJhJhAAwkwgBYCYRktpv16vN7tNnAVC8RxGy365Xq/V23zRN0+w2q9UCxXW3CUd4cCbxsXebJWq9CAEY5V0RstuE3ey3625ixBGSbNDaR+vwl13u9vGW++169VDYzaitV6vL2e+36yUyFKBOkyJktt2mU3lbeXL99v7d5YCbXSu0xnr6NFun0JsT0bkD/LB3RMh+u0520a7E9whZaKbsgRE51T79KA8BflYmQloVdbPrmcjK1Prey/Oeknu/1r9FSP7qP1fgL8cJ0fPixYtHu5MhAE3TJBFyWRkI9fFavjNrIUmGTE2Q7hYD45zMSkl/hEyd+Bq9EtIZisgQgKaJIyQdXOw2+QjJr21nciCexRpbtNsxNj5C4t+mu8YyVPaj8Ay/Yt8AynoIQCdCMtNT/XdkJd/kC/ScK/ZOuZ8/kTU2QnpT7TK9ltzyZRgC0DRNJkKiq+uBm3pbWw+U1FdEyLxRSPfTcesl0cxd3/3FIgSgeWYU0irmQxU1/dm49YrnI6R75AcRcj2p/NgnSRERAtBEEZLewXuZ4+l7tPBazQeXw+esG7xkIisq89E2rYcE8/NY7f3FYxFrIQBNk9yR1V1BvhXX3qfT99v1ar0erqczrthHTmTlt2+denyqafqNOP7tk+jRSIMQgPS5kNZV/+2u1/4XnHRHKXnTC+7UCEmO0DMj153WSn+T227DtvlTlyAATdO850297ZI7+sGNTISEvu1Sn8w79d6KGx06eUvWZne7+So867jfX3t5Oh0g9Z6XvU+surOfNp/+OpbOcO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9Fr8j63a9fb/W7x+FxDHxighpbX39rD0n1K7yQ0V6ZAHvbvYgQq7Z0V7hj0YjM84AWJ4ICf3eclPvPSR6pv9bP2zVzs7GEyKkdy3k1D1eE1X5B2vm4wYU0QOH8fOHrSQdnBSLxyLWQqAcIiT0W245vXs1HtXOzk2+yS2/1z10CuuECOm7I6tnlXrkMvnD7ZLFmUyE9KZAeiLtm9MMQqAkIiT0W24Ukn2+41r3T32PhXQf+5g5kZUruItHSOYGsXRlJP1lkxm1/JEkCBREhIR+b346fajuv1Kr5IYoS/InE2HpXnoXJ5LtMjuKnhlJ3pJ1ON1uvrrdynU+X+8i8HQ6FEuEhH5fGiHvq7rTf6POcCR321r4QWb9H/g8ERL6fW2EfMvbCd/5FwNGESGh3xdHCMAiREjo96Vv6gVYjAgJ/UQIwDQiJPQTIQDTiJDQT4QATCNCQj8RAjCNCAn9RAjANCIk9HtNhAD8mmcqpwi5+vQ/IsBnPFM5RQgAcxVWe0UIQD0Kq70iBKAehdVeEQJQj8JqrwgBqEdhtVeEANSjsNorQgDqUVjtFSEA9Sis9ooQgHoUVntFCEA9Cqu9IgSgHoXVXhECUI/Caq8IAahHYbVXhADUo7DaK0IA6lFY7RUhAPUorPaKEIB6FFZ7RQhAPQqrvSIEoB6F1V4RAlCPwmrvcxGiaZqmvb8VQ4RomqbV1opR0KkAUBcRAsBMIgSAmUQIADOJEABmEiEAzCRCAJhJhAAwkwgBYCYRAsBMIgSAmUQIADP9B61NTsyOm6NXAAAAAElFTkSuQmCC" alt="" />、

您也可以使用可选参数来过滤对子元素的搜索。

下面的例子返回类名为 "1" 的所有 <p> 元素,并且它们是 <div> 的直接子元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.descendants *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("div").children("p.1").css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body> <div class="descendants" style="width:500px;">div (当前元素)
<p class="1">p (儿子元素)
<span>span (孙子元素)</span>
</p>
<p class="2">p (儿子元素)
<span>span (孙子元素)</span>
</p>
</div> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhMAAAEXCAIAAACYuFH4AAAQD0lEQVR4nO3cO5aqQBQF0J6RI3JAzsa5aGJiYmbKAHiBP6gPcn3SIr33Imi1hKKDe6gq8KcFgIifT3cAgC8jOQCIkRwAxEgOAGIkBwAxkgOAGMkBQIzkiNpvVj/r7ad7AfA5/5cc+83q52e12bdt27bb9c/PBDV1u74f4UlP0mNv11OUeMkB/HXzSI7t+r6b/WbVD4o0ObIGnX10Dn/Z5XafttxvVj9P3XczqvXPz6X3+81qiugEmJk3JsfLtutewe3EyPXl49XlgOttJ6vG+u9udrpQjYek7wBL9Pnk2G9W2S66BfiRHBNNhz0xIp663U9iEGB5wsnRKaTrbWW2qlDiqxfjlUr7uLK/JUf5Wr9U1y/HuSfOmxcmnu1OdABLF0qOy6z/vSxeq3ZhnSOLjmhw9FsMjGoKqyD15IjObo1e5egNPEQHsHCR5MiHEtt1OTnKy9WF8p9OVY2t1d30Gp8c6dn010+Gqn2SmfdTrA2XrHUACxZIjsIcVP3equxFuS6/cn3eq/Kvz1aNTY5qmF3m0LKbtww6gKULJkdyLT1wV26n9UAlfUdyvDbm6L87bi0kmZ6r3SAsOYBlm2rM0anhQ4U0/2zcWsT/J0f/yE+S49qp8kgnCw/JASxbIDnyW3AvEzm1JwGvRXxwhfuVNYG3zFYl1T1p03mmrzxZ1d1fOvKwzgEsXOjeqv6i8K2mVp8h329WP6vVcBl94fp85GxVuX2n62lX89AbcfzbO8mTjIYcwIJFn+foXOPfblut//pIf0xS32GszkaTIztCZdqtP3eVn8ltt/e25a4LDmDpPv9bud1KO/qBi0Jy3L/brfDZ5FL1Xtrk0NkvV623t9uo7o8m7vfXb3mGHPhTPp8c4WL78jPh8d9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As/BFlVNyAMzCF1VOyQEwC19UOWedHAB/zWdr70iSA2BGPlt7R5ppcgAQJTkAiJEcAMRIDgBiJAcAMZIDgBjJAUCM5AAgRnIAECM5AIiRHADESA4AYiQHADGSA4AYyQFAjOQAIEZyABAjOQCIkRwAxEgOAGKWkBwA/L4pqnpCcgAsyhRVPTFJcgCwYJIDgBjJAUCM5AAgRnIAECM5AIiRHADESA4AYiQHADGSA4AYyQFAjOQAIEZyABAjOQCIkRwAxEgOAGIkBwAxkgOAmH9vngJw+GoUMQAAAABJRU5ErkJggg==" alt="" />

jQuery find() 方法

find() 方法返回被选元素的后代元素,一路向下直到最后一个后代。

下面的例子返回属于 <div> 后代的所有 <span> 元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.descendants *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("div").find("span").css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body> <div class="descendants" style="width:500px;">div (当前元素)
<p>p (儿子元素)
<span>span (孙子元素)</span>
</p>
<p>p (儿子元素)
<span>span (孙子元素)</span>
</p>
</div> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgYAAAEoCAIAAACsE64sAAAQ7ElEQVR4nO3dO5qiQBQGUHfkilgQu3EvTWIyiVmnLoAJvGJRVCnaPlDP+QimbZSLwf2pKuhZ9QDQ933fr15dAABLIRIACCIBgCASAAgiAYAgEgAIIgGAIBIACCIBgCASAAgiAYAgEgAIIgGAIBIACCIBgCASAAgi4byuXa+azaurAHiKayKha9er1brt+r7v+02zWj2gWW6a4QgXKsmPvWke0btFAvBFXhEJm2b4mK5djxMgj4TJDslnJIc/fOSmy/fs2vXqouFjZu29Wh2q79r1IzIR4HVujoSbbZpRJ03yIX48/XQ4YLNJQmiuP5eZlFDt+1ntAG/u2ZHQtevJR6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3/kCMF1gQ42R2vCXV9/xUfWU25ZIfFhZHoAYsKHGKGwYSnobYmV5AGLAhhqThQ1J160aVTe61CnWUgYgCmyoMXIbvnzKJ33bEDYEIAZsqDFSG/788imfzHrK6CiDWQY21BiFDf/CJ+2cMlaWB0AAbKgxV7Wh5PuGWFkeABGwocYobNjnk/K3KPj2NQAiYEONkdrwp5d9PvhlHgAZABtqjNyGL77lAxsCkAGwocbAhgBMENhQYxQ2fMIHNgQgA2BDjZHa8McXT/jAhgBkAGyoMQob9vjAhgBkAGyoMbAhABMENtQYw3t5EASZWICWTPttgSAzGKAl4hdmMBgcPe/yGQAAwGdNUhsiCIJ83oENEQRBukewIYIgCA1siCAI0j2CDREEQWhgQwRBkO4RbIggCEIDGyIIgnSPYEMEQRAa2BBBEKR7BBsiCILQwIYIgiDdI9gQQRCE5v8HJvn8asGB5gAAAABJRU5ErkJggg==" alt="" />

jQuery 遍历 - 同胞(siblings)


同胞拥有相同的父元素。

通过 jQuery,您能够在 DOM 树中遍历元素的同胞元素。

在 DOM 树中水平遍历

有许多有用的方法让我们在 DOM 树进行水平遍历:

  • siblings()
  • next()
  • nextAll()
  • nextUntil()
  • prev()
  • prevAll()
  • prevUntil()

jQuery siblings() 方法

siblings() 方法返回被选元素的所有同胞元素。

下面的例子返回 <h2> 的所有同胞元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.siblings *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("h2").siblings().css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body class="siblings"> <div>div (父元素)
<p>p</p>
<span>span</span>
<h2>h2</h2>
<h3>h3</h3>
<p>p</p>
</div> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkwAAAFfCAIAAAAzrAQ8AAAM/0lEQVR4nO3dL5Ab5xnA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jkAwhI5AMISOQDCEjkAwhI5AMISOQDCEjkAwhI5AML6P1c0qCBXP4VbAAAAAElFTkSuQmCC" alt="" />

您也可以使用可选参数来过滤对同胞元素的搜索。

下面的例子返回属于 <h2> 的同胞元素的所有 <p> 元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.siblings *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("h2").siblings("p").css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body class="siblings"> <div>div (父元素)
<p>p</p>
<span>span</span>
<h2>h2</h2>
<h3>h3</h3>
<p>p</p>
</div> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkcAAAFbCAIAAABQ3b3dAAAMTklEQVR4nO3cXXbTVhuAUc8oI8qAMhvmIidBJCgEl5+IwkcwbRpgWd+F/yRbjhVkY+vV3utctPaJpN70WedI8qAAgCgGh74AANgZVQMgDlUDIA5VAyAOVQMgDlUDIA5VAyAOVQMgDlUDIA5VAyAOVQMgDlUDIA5VAyCO36laAgB/lqoBEMfeq/YbfwgAz6VqAMShagDEoWoAxKFqAMShagDEoWoAxKFqAMShars1HqVJlh/6KgD66piqNh6lSZKOxkVRFEWeJUkH+6BqAIcUsWp5tjxM5eiLD8v/vH4J2yyuqtHsJJlezXiUdjHTAJ1ytFX7bXlWF488S5I0y6fHHuejLN3PUvDJtVp9bgHYmWhVG4/S9UPUr/vyLGkfmTxrtFArT7deA9ibA1etFIUs37ADWdOkjYuemmo8tZU5Pf0uM7PtvpqsAezTAas2vSu1+F/8LHA199XWutQ4arNTZBs3JWcpTbK80bKrsgBrfFetsmCTNYA9OlzV1tdQlS3B8tcrUzdGbXX7cVGQuhXUMi8bvl0eadsCbKXPi0uu+6PaLVIAduNgVavZGNz8DOTav9Q35ol1UJ5Vv9kWl6ZV27hgS0f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VVsu1KZOB8XJWavTAXAoqlZTtcFpq9MBcCiqZq0GEIeqVe+ivajpHABdoWqlp/mHxYntR4AuU7Xi7EVxMn9ZTdIAOk3V7DcCxKFqqgYQh6qpGkAcqqZqAHH0umoABKNqAMShagDEoWoAxKFqAMShagDE0aOqGYZhGD0ZLaiaYRiGcWSjhS5UDQCaUTUA4lA1AOJQNQDiUDUA4lA1AOJQNQDiUDUA4lA1AOJQNQDiUDUA4lA1AOJQNQDiUDUA4lA1AOJQNQDiUDUA4lA1AOJQNQDiUDUA4vhDVQOAP0bVAIhjj1UDgOOkagDEoWoAxKFqAMShagDEoWoAxKFqAMShagDEoWoAxKFqAMShagDEoWoAxKFqAMTxf3AZmDBlT1SKAAAAAElFTkSuQmCC" alt="" />

jQuery next() 方法

next() 方法返回被选元素的下一个同胞元素。

该方法只返回一个元素。

下面的例子返回 <h2> 的下一个同胞元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.siblings *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("h2").next().css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body class="siblings"> <div>div (父元素)
<p>p</p>
<span>span</span>
<h2>h2</h2>
<h3>h3</h3>
<p>p</p>
</div> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkwAAAFfCAIAAAAzrAQ8AAANqklEQVR4nO3dP4wj133A8e2uEILAhSqXLlKoUBFV6eLWQOD0duXajUqlSJXi6jSq3Lhy5TTpEsC1kQgwZu9Oo5PnLFF/7sbyRRFlS2cL91zscvlIDpdcvcfl428/H0yhJYePT42+eG9mqLMEAEGdHXsCAHAoIgdAWCIHQFgiB0BYIgdAWCIHQFgiB0BYIgdAWCIHQFgiB0BYIgdAWCIHQFgiB0BYIgdAWCIHQFgiB0BYIgdAWCIHQFgiB0BYIgd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dAWCIHQFgiB0BYIgdAWMeJHADcGpEDIKzbixwAnBaRAyAskQMgLJEDICyRAyAskQMgLJEDICyRAyAskQMgLJEDIKy/AoLzS4iPYR9VAAAAAElFTkSuQmCC" alt="" />

jQuery nextAll() 方法

nextAll() 方法返回被选元素的所有跟随的同胞元素。

下面的例子返回 <h2> 的所有跟随的同胞元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.siblings *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("h2").nextAll().css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body class="siblings"> <div>div (父元素)
<p>p</p>
<span>span</span>
<h2>h2</h2>
<h3>h3</h3>
<p>p</p>
</div> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlAAAAFdCAIAAABD9sRRAAANFElEQVR4nO3dL5Ab1x3AcTGDTKcTYBQYUBBwoEZlDe1Mp+UxCg4JTEFRweGSoJCioJqUtTPBnTYzmZX/rO2s6yhx7E3qppYT24nnXoGk00ralXTdlbTK7/OZB2xp72mP+Dvv7a48SAAQwODQJwAA+yB4AIQgeACEIHgAhCB4AIQgeACEIHgAhCB4AIQgeACEIHgAhCB4AIQgeACEIHgAhCB4AIQgeACEIHgAhCB4AIQgeACEIHgAhNBx8DIA2C/BAyCEQwav2zkBoJbgARCC4AEQguABEILgARCC4AEQguABEILgARCC4O3NeJRnRXnoswCI6kiCNx7lWZaPximllMoiy44wHYIHcEjBglcW82kWZj9/sfrn1VPY5Pystjo6yyZnMx7lx1hwgKNyjMH7v5VFXVfKIsvyopzMPS5HRb6bBeTaFV59iQHoTKDgjUf56hT1q8WyyNr3pyy2Wt5VD7fKA9iZ/gav0ouibNjSrMlV41KpJijr9kYnH99lgTZdw1M8gF3qZ/AmV8DO//Wftq/mGt5Ksrbu3fQjisZdzmlls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oJnGIZhHHTsKzr9Cx4AbEfwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAhB8AAI4ciDd/D/mckwDMPY59hXdATPMAzDOOjYV3T6GjwAfvQET/AAQhA8wQMIQfAEDyAEwRM8gBAET/AAQhA8wQMIQfAEDyAEwRM8gBAET/AAQhA8wQMIQfAEDyAEwRM8gBAEr/73H56mwSCdDtPpyfw7tq+1+igADknw1gVv0ryJq4M0OEnDmmMBOAKCty54V6trumE6WXoFgOMheBu2NKuuDtLJaauPA+BQBO9iwRtcbfVxAByK4FnhAYQgeFtfw7tWk0AAjoXgbbhLc5q8YTqxnwlwzARv7ZbmtXQyewhP7QCOmuBd4BoeAMdL8AQPIATBEzyAEARP8ABCEDz/WwJACIIneAAhCJ7gAYQgeIIHEILgCR5ACIIneAAhCJ5hGIYRaOwrOoJnGIZhHHTsKzr9Cx4AbEfwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAhB8AAIQfAACEHwAAjh8MEDgL0RPABCOEzwAKCfBA+AEAQPgBAED4AQBA+AEAQPgBAED4AQBA+AEAQPgBD+B7/EJVfPqghjAAAAAElFTkSuQmCC" alt="" />

jQuery nextUntil() 方法

nextUntil() 方法返回介于两个给定参数之间的所有跟随的同胞元素。

下面的例子返回介于 <h2> 与 <h6> 元素之间的所有同胞元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.siblings *
{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("h2").nextUntil("h6").css({"color":"red","border":"2px solid red"});
});
</script>
</head>
<body class="siblings"> <div>div (父元素)
<p>p</p>
<span>span</span>
<h2>h2</h2>
<h3>h3</h3>
<h4>h4</h4>
<h5>h5</h5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ACRCtlJUWwISJVqrjmpZmAUzFmNH6f6c5fUU8Q0TbAAAAAElFTkSuQmCC" alt="" />

jQuery prev(), prevAll() & prevUntil() 方法

prev(), prevAll() 以及 prevUntil() 方法的工作方式与上面的方法类似,只不过方向相反而已:它们返回的是前面的同胞元素(在 DOM 树中沿着同胞之前元素遍历,而不是之后元素遍历)。

---------------------jQuery 遍历- 过滤(重要)-----------------------

缩小搜索元素的范围

三个最基本的过滤方法是:first(), last() 和 eq(),它们允许您基于其在一组元素中的位置来选择一个特定的元素。

其他过滤方法,比如 filter() 和 not() 允许您选取匹配或不匹配某项指定标准的元素。

jQuery first() 方法

first() 方法返回被选元素的首个元素。

下面的例子选取首个 <div> 元素内部的第一个 <p> 元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("div p").first().css("background-color","yellow");
});
</script>
</head>
<body> <h1>欢迎访问我的主页</h1>
<div>
<p>这是 div 中的一个段落。</p>
</div> <div>
<p>这是另外一个 div 中的一个段落。</p>
</div> <p>这是一个段落。</p> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdcAAADgCAIAAADe7rs3AAAZd0lEQVR4nO2dS2gdV5qAa3cXWggv7koEIYIJgxB3YS+EQwgWg5rBIGxoEAbXSqhxYLywYRjwQNQDY4aiwQ3dNm0a2h4wQ/DYMAWOAx0iMISxm0xsEC5QJsRjHGVhvBBDcxd3V7Oo13nW41aVjuR8H2dhl+pxqu49X/31n1PnejEAALjDc10BAICfNVgYAMAlWBgAwCVYGADAJVgYAMAlWBgAwCVYGADAJVgYAMAlWBgAwCVYGADAJVgYAMAlWBgAwCVYGADAJVgYAMAlWBgAwCVYGADAJVgYAMAlWBgAwCVYGADAJVgYAMAlWBgAwCUHaOGnV9+fnZtfXDm/eTm481//e3AHrmay983tiyc+vh5Vrrj/Yvv+neDy5try/Nzs+1efNj7U+NWT21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sq1iu8qx0bAKCabi0cC8kAWyq2N4wHNNciV6cWC5vVLyUorGkNDAwAzencwuky/WG9YXDbkb8r7gWGvLByQsaheHJWRcjIaAsBAMrpw8KFjiwqErexDDjuimoLG+8hYiZZXqHn+gLAz42uLZwauEjSViWGjZ113WluCgsXHi7vb7R2MyJpAKhPhxY25SEM7wUn8jpUsbDgU6H3zSRUsbbGbkb1dNIdkZ8AAAutZ/NJHaMPAhPX0d6cK8JkdxYuSZwUf5I3lYZQ1LBwdovixToAsNF6vLAf1p4wR1Fi+cDhjqzVOCMhhepKKK+8wlGdkcDCAFBFm1g49GsaNVFZ6KJfq4mFTW/cxYKXlcHEdTIS2XXBwQBggVneAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFyChQEAXIKFAQBcgoUBAFzy/+CQQbqaX2/dAAAAAElFTkSuQmCC" alt="" />

jQuery last() 方法

last() 方法返回被选元素的最后一个元素。

下面的例子选择最后一个 <div> 元素中的最后一个 <p> 元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("div p").last().css("background-color","yellow");
});
</script>
</head>
<body> <h1>欢迎访问我的主页</h1>
<div>
<p>这是 div 中的一个段落。</p>
</div> <div>
<p>这是另外一个 div 中的一个段落。</p>
</div> <p>这是一个段落。</p> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZIAAADvCA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AMdAWwDgGGgLABwDbQGAY6AtAHAMtAUAjoG2AMAx0BYAOAbaAgDH+H92L8jz6bghtgAAAABJRU5ErkJggg==" alt="" />

jQuery eq() 方法

eq() 方法返回被选元素中带有指定索引号的元素。

索引号从 0 开始,因此首个元素的索引号是 0 而不是 1。下面的例子选取第二个 <p> 元素(索引号 1):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("p").eq(1).css("background-color","yellow");
});
</script>
</head>
<body> <h1>欢迎访问我的主页</h1>
<p>菜鸟教程 (index 0).</p>
<p>http://www.runoob.com (index 1)。</p>
<p>google (index 2).</p>
<p>http://www.google.com (index 3)。</p> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX4AAAELCAIAAABRV3rZAAAd1UlEQVR4nO2dTYgcV37A69aHOQgf+jSYQRhhghB1kA6DjDEagpYgGCRYGAyq06BFC9FBghBQwNpARCgWHNiVWRFYKSCCUSRIgWzDGg8ITKRlYwkGNchZrAh7fBA+DGHpQ98qh/p63/XR1fO6e34/CqHpro9X1e/96v/+rz6CFADgwAl8FwAADiOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8gHoAwAOoBwA8MLV6nl5/58jq2vGNDy9dje/+1//2Uaa+mOz96c7lkx98PKqdcf/FzoO78dVLm+trq0feuf609abGr5/cubZx9Oj25/uditqdURwGFVHSegWTh1srw7W19c1Llz765MED60+4/+nWcHV986NPPnvy3f5kukJnjF8/uXP55NHo4Zs+1gYLxrTqkWp+GNe28orxy/vbJ07Hu/ZaPNl/8Si+ePLodtK6PU/2HsfnVgdBEATB4JRrI2m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Y/YmjEcOPZRbNOW9rOrRMR06k+PdBTlo9VRJwZojq6OleFqoQ9sp1OOLg1VP0xZhmrmoI0lUNZX8b6Uu9jVX7e54iHoaJjTmP+qp1FNzZF29oVLGzeWh7gTq8cUM1eOKlB3bUjcnfRollR2yShMb0gx9zWUvpHS2teV6rOkMV4NXcix6YqpX94hr7K6eBrkei3qaHFmre4ryNEwy23eKXI8POqjH1lqET9RxCklFYhq1SZpH/jwMpX5TGIam1jT9XHKuXU65Fh0B8/5pB1BN28tHS+kzFCdy47iSYU3CcbSUNi1HuNwFmUI9aujQWD0djqzJlIYcTrWAWi8106m/FC46ELqop2of1UzyJ/n8QnJC659HSdrSPHrNUZtSn3NpS8k7ox0jOS9hDNlMB0NbNkqsHS59OxZRKrPpP6X9m27qUd3TQj31R1Yssen0Vc3kqDWOIy+JXcwAwkyZzZ3r5h5To9naRM8eqU1DTEGzftV8sZgpEz3mQT0Hhkf1tEjzzB2YR2MB5aPleZTeLswSr1HP4lAmVYq/+rODkL5Ibb3DxWCWPu6fpaujiwbqaUhNLmcqnIkggKWEpxQCgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB4APUAgAdQDwB44P8BEJ0t5Kz5ISYAAAAASUVORK5CYII=" alt="" />

jQuery filter() 方法

filter() 方法允许您规定一个标准。不匹配这个标准的元素会被从集合中删除,匹配的元素会被返回。

下面的例子返回带有类名 "url" 的所有 <p> 元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("p").filter(".url").css("background-color","yellow");
});
</script>
</head>
<body> <h1>欢迎访问我的主页</h1>
<p>菜鸟教程 (index 0).</p>
<p class="url">http://www.runoob.com (index 1)。</p>
<p>google (index 2).</p>
<p class="url">http://www.google.com (index 3)。</p> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY8AAADmCAIAAACidJ6WAAAdOElEQVR4nO2dT2jdSJ7H6/YOPpgc3sk0xoTQLMbokBxMmqaJWTwsAZPAgAlEJ+MhDZtDAsuCF+JZ2LCIgR6YSZgwMMlCWJpsDCtIp2FCGwLNJkNvJ2AicG/T2ZC4DyEHswzv8G7ag/7Vr+pXpdJ7erbK/n4QIX5Pf0p6VR/96qeSJFIAAPABcdgFAAAAJ2ArAIAfwFYAAD+ArQAAfgBbAQD8ALYCAPgBbAUA8APYCgDgB7AVAMAPYCsAgB/AVgAAP4CtAAB+AFsBAPwAtgIA+EGrtnq+cXJ6ZnZ+6dL6tejef/1vm6sel+Hed3evnP7si6R2xv1X2w/vRdfWVxZnZ6ZPbjxvvKnBm2d3ry/Nza093h+pqKOTRIGoCOPGKxhurU71Z2cXV9bXb9x++ND4E+5/udqfWVy5cfurZz/tD8crdMbgzbO7V07PhVvv21gbOJq0aSvSWIKoVgwVg90Hawtnox1zxR/uv3oUXT49txY3VsBw72l0fqYnhBCid8a2kTRN0/0vL/bEiLuRpi9/szhdLn5y43krLTlNh/s/v83YffbVw4cPHz68F11bX19fv7Q0Pzs7OzPdm7+5k6ZpHDK2Gry4eXZhbetHh7I83/jIZd/3769Is524uj3Wrr16cH1pbqpY2WozX5E9bpMRXA8mTYu2InXYuQoP955Gy/1soX4Yk6o6+PD25fa96FdLpyoFNNRHmg63r/alWljrK9oUxbk775ps7PnGSWlb5+68zj5v2qjKtvJ4rVc/d1lO3Vbvv904k4t6ZvV+jbFobGY80u/unJNmO/H5k3GcTI+YEKLfKCaFrY4TNbai9df6sw7jUGpYK/fdqty7Py3LzVF2iWHbvZWNf3AuVJqmabr/eK2JrxRdrW41aozv769IO3Qiz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JsqxGOLCdXJh9VLaDWS02O6i8FfXWJcW1VNalqJvpJPr+UaNFyDWGcNpSVXtnU1tfmXNpSdGe0Y0RzLGxgyB0MbdkwNvYE9e0Y3KrMpv+U5m9Gs5Wqqwa2qj+ycom5M141k6XWWI48ORfI2UzQBSb/DAa+K+c0W5Ow/hCpTamMgVuHr1v4mf7RIyvYqmt0xFYNUladA7LS8NBXWs5K6YaDDtARW/lEmSAq/mpPKFIqJjV1W/1gkgpvnyNXR48osNUI1OSlxsKa1ALgOINnhwIA/AC2AgD4AWwFAPAD2AoA4AewFQDAD2ArAIAfwFYAAD+ArQAAfgBbAQD8ALYCAPgBbAUA8APYCgDgB7AVAMAPYCsAgB/AVgAAP4CtAAB+AFsBAPwAtgIA+AFsBQDwA9gKAOAHsBUAwA9gKwCAH8BWAAA/+H9RqbG76HmfLgAAAABJRU5ErkJggg==" alt="" />

jQuery not() 方法

not() 方法返回不匹配标准的所有元素。

提示:not() 方法与 filter() 相反。

下面的例子返回不带有类名 "url" 的所有 <p> 元素:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("p").not(".url").css("background-color","yellow");
});
</script>
</head>
<body> <h1>欢迎访问我的主页</h1>
<p>菜鸟教程 (index 0).</p>
<p class="url">http://www.runoob.com (index 1)。</p>
<p>google (index 2).</p>
<p class="url">http://www.google.com (index 3)。</p> </body>
</html>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWcAAADgCAIAAABQGDAOAAAc90lEQVR4nO2dT4gcR5bG41aHPjQ+1KkxTWOEWYTIg3RoZIxRs/SwCBoJBhqD8tT0oIHVQYJlQQvuWVixJANemJEZsTDSgliMVoJNkG0Y4waBWWmYtQSNEto7WCvs9kH40CxDHeqWe8h/8SJeRMaryuqq6v5+vEN3VWRkZGS8L1+8yMxSOQAASFDTbgAAYM6AagAAZEA1AAAyoBoAABlQDQCADKgGA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w7mi21dp/liT8FnTP9KAaX3XqF92hdf5JM5tNrcaF9yz5R298YHzCXBEgGzLaVMNQZKeLcJ+YV4LcP9loz4Na4yWKIvJ/c1nsqJS7LdYRMs3XP2KcW/vI0Zusr5o18XGR04X8DbFOWuHARhTGn0Kz12zVcGmKsGfJKKq3bZnINqEMI7GdzaxOBpK8Bjktoaphi7rj9ISkNLQyWRKVYXzzvz7KOipltIU7nKIk600t6wn10XEbu2YovIdZzXX5kL8hAZrkdE6r1/whkVaxtGeNNqWxUlEcB4cLzNUMwYYIqWrw133+E/9gMOBGs2e8FI7eXCTIae+yFG2h8bE5ttlMRZRkHs+u98jleJyqYcN1HSfP/oYctWo0CbCWnrWx0hkCr7cOCqohYhqqETqYucLV6U3jZpSX/xvDqKtSrYczhVgjcPI++7FGoxotPeubPtQ6Gu735kFANURMXDV8oaVnX+buyKdx2jh2cb4TZkrdVSl3I8k1zpXXcE7dfb5q5BPsJEynsqHXOLpqBOQ1HKoR0rNO2ajaE5gLdR8U8hrBjKwaroGufWJmwomK6Nm+kJQG/TyKyEQjiiLOEcYvRVPCNDNYRc788VkdaGaXaW8ZQXZ1+WRXLpiatH50tDav11D8DRlDNcwLdrBqjNCznMgx+YpmA3NcWiJlninIiJvRVaMZ2k0h+klZXpuIW3PROM2FomGfdNMLuixlbUUPxuojOgdnAyWuM6xt49Q5Q7H349A4o5h9Kt3fjKYapmwIVKO9Z/UWc1eeppBn1Hh6nmiynu0CNpN85pWfYgQVk4SbU6R1yj0GYROR2WI+0wN2pAHV8DN11RCkNGYOiIbFHOqGldMwpofAYuqqMU/UCYTqv+4cW5uq567p1HwwSSntnmM3Ro8EqIaIlrzFWHiTHgDMDniXFwBABlQDACADqgEAkAHVAADIgGoAAGRANQAAMqAaAAAZUA0AgAyoBgBABlQDACADqgEAkAHVAADIgGoAAGRANQAAMv4fBzDbBCAkMaAAAAAASUVORK5CYII=" alt="" />

上面选择器反对的都是jQuery对象,可以直接使用jQuery的方法。

例如:

bigParent 就是一个jQuery对象。
var updateTotalNum = function(obj) {
var bigParent = $7(obj).parents(".elaquesTitle_father");
var quesNum = bigParent.find(".nmb").length;// 获取到题的总数
var quesEveryScore = bigParent.find(".el_modifiedGrade").val();// 获取到每道题分数
bigParent.find(".el_BigTitle").find(".numTotal").text(
parseFloat(quesEveryScore) * parseFloat(quesNum) + "分;共")// 设置分总数
bigParent.find(".el_BigTitle").find(".numQues").text(quesNum + "题)")// 设置题总数 }

jQuery遍历文档(重要)的更多相关文章

  1. jquery获取文档高度和窗口高度的例子

    jquery获取文档高度和窗口高度,$(document).height().$(window).height() $(document).height():整个网页的文档高度 $(window).h ...

  2. js、jQuery 获取文档、窗口、元素的各种值

    基于两年开发经验,总结了 javascript.jQuery 获取窗口.文档.元素的各种值 javascript: 文档:是整个document所有的内容 浏览器当前窗口文档body的宽度: docu ...

  3. python 全栈开发,Day54(jQuery的属性操作,使用jQuery操作input的value值,jQuery的文档操作)

    昨日内容回顾 jQuery 宗旨:write less do more 就是js的库,它是javascript的基础上封装的一个框架 在前端中,一个js文件就是一个模块 一.用法: 1.引入包 2.入 ...

  4. python全栈开发day48-jqurey自定义动画,jQuery属性操作,jQuery的文档操作,jQuery中的ajax

    一.昨日内容回顾 1.jQuery初识 1).使用jQuery而非JS的六大理由 2).jQuery对象和js对象转换 3).jQuery的两大特点 4).jQuery的入口函数三大写法 5).jQu ...

  5. 使用jQuery匹配文档中所有的li元素,返回一个jQuery对象,然后通过数组下标的方式读取jQuery集合中第1个DOM元素,此时返回的是DOM对象,然后调用DOM属性innerHTML,读取该元素 包含的文本信息

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. jsonp 遍历文档

    遍历文档 将html解析成一个Document后,就可以使用类似Dom的方法进行操作 File input = new File("/tmp/input.html"); Docum ...

  7. jQuery 的文档操作

    在 js 中也有DOM操作,也可以进行 增删改查 ,但是通过 js 的DOM操作会发现,我的天哪,代码好多.但是 jQuery的文档操作就少了很多. js 中 DOM 的示例 : var box = ...

  8. bs4--官文--遍历文档树

    遍历文档树 还拿”爱丽丝梦游仙境”的文档来做例子: html_doc = """ <html><head><title>The Dor ...

  9. 使用Python爬虫库BeautifulSoup遍历文档树并对标签进行操作详解(新手必学)

    为大家介绍下Python爬虫库BeautifulSoup遍历文档树并对标签进行操作的详细方法与函数下面就是使用Python爬虫库BeautifulSoup对文档树进行遍历并对标签进行操作的实例,都是最 ...

随机推荐

  1. graphviz使用

    官方网站:http://www.graphviz.org/ Graphviz (Graph Visualization Software) 是一个由AT&T实验室启动的开源工具包.DOT是一种 ...

  2. RHCSA考试

      RHCSA_PDF版传送门:https://files.cnblogs.com/files/zhangjianghua/RHCSA%E8%AF%95%E9%A2%98.pdf RHCE_PDF版传 ...

  3. [转]grep 在文本中查找内容

    转自: http://www.lampweb.org/linux/3/27.html 功能:grep系列是Linux中使用频率最高的文本查找命令.主要功能在一个或者多个文件中查找特定模式的字符串.如果 ...

  4. 什么是App加壳,以及App加壳的利与弊

    非著名程序员涩郎 非著名程序员,字耿左直右,号涩郎,爱搞机,爱编程,是爬行在移动互联网中的一名码匠!个人微信号:loonggg,微博:涩郎,专注于移动互联网的开发和研究,本号致力于分享IT技术和程序猿 ...

  5. 如何写一套下拉刷新的控件?《MJRefresh原理浅析》(附Demo下载地址)

    相信大家有很多人在做项目的时候都在使用MJRefresh 控件来实现下拉刷新的功能: MJRefresh经过不断的重构与更新迭代,现在不管是功能上还是代码结构上都是相当不错的,都是很值我们去学习的. ...

  6. android压力测试monkey简单使用

    monkey是android sdk自带的压力测试工具,简单使用如下: 用adb shell进入adb shell环境后,用下面命令进行测试 monkey -p com.xxx.yyy -v num ...

  7. typeAliasesPackage 配置

    mybatis 的 xml 文件中需要写类的全限定名,较繁琐,可以配置自动扫描包路径给类配置别名,有两种配置方式. 方式一: mybatis-config.xml 中配置 <typeAliase ...

  8. [转]unity之LOD

    LOD技术有点类似于Mipmap技术,不同的是,LOD是对模型建立了一个模型金字塔,根据摄像机距离对象的远近,选择使用不同精度的模型. 它的好处是可以在适当的时候大量减少需要绘制的顶点数目. 它的缺点 ...

  9. Python全栈 MySQL 数据库 (表字段增、删、改、查、函数)

    ParisGabriel              每天坚持手写  一天一篇  决定坚持几年 为了梦想为了信仰    开局一张图         查询SQL变量 show variables 1.表字 ...

  10. 孤荷凌寒自学python第五十四天使用python来删除Firebase数据库中的文档

    孤荷凌寒自学python第五十四天使用python来删除Firebase数据库中的文档 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数据库 ...