MENU
Reduction
.eq(int index) Reduce the matched elements to the one at the index. .filter(String/Element/jQuery selector) .filter(function (int index, Element e) f) Reduce the matched elements to those that further match. .first() Reduce the matched elements to the first. .has(String/Element selector) Reduce the matched elements to those that have a matching descendant. .odd()Reduce the set of matched elements to the odd ones in the set, numbered from zero..even()Reduce the set of matched elements to the even ones in the set, numbered from zero..last() Reduce the set of matched elements to the final one. .not(String/Element/Array/jQuery selector) .not(function (int index, Element e) f) Remove elements from the set of matched elements. .slice(int start [, int end]) Reduce the matched elements to a subset. |
RESETRUNFULL
<!DOCTYPE html><html><head>
<script src="jquery-3.5.1.min.js"></script> </head><body>
<div>
<span>1</span>
<span>2</span>
</div>
<p>A</p>
<p>B</p>
<p>C</p>
<script>
alert($('p').length); // 3
alert($('p:last').index()); // 3
alert($('p').index(
document.getElementsByTagName('p')[0])); // 0
alert($('p').add('span').length); // 5
alert($('span:first').next().length); // 1
alert($('span:first').next().addBack().length); // 2
alert($('span:first, p:first').nextAll().length); // 4
alert($('body').children('p')[1].innerHTML); // B
alert($('p,span').not('p')[1].innerHTML); // 2
alert($('body').find('p,span').slice(1,3)[1].innerHTML);// A
alert($('p').next().next().first()[0].innerHTML); // C
alert($('*').has('span').filter('div')[0].innerHTML); // contents of <div>
alert($('span').pushStack(
document.getElementsByTagName('p')).length); // 3
</script></body></html>