Nextuntil () gets all the sibling elements that each element follows, and when there are parameters, the search stops until the element that matches the parameter of the method is encountered. The new JQuery object returned contains all of the following sibling elements, but does not include elements that match the selector, the DOM node, or the passed JQuery object. If there are no arguments, all the following sibling elements are selected, in the same way as the. Nextall () method.
Grammar one:
Copy Code code as follows:
. Nextuntil (Selector,filter)
Syntax Two:
Copy Code code as follows:
. Nextuntil (Element,filter)
Detailed description
Given a JQuery object that represents a collection of DOM elements, the. Nextuntil () method allows us to search for the sibling elements followed by elements in the DOM tree, stopping the search when an element that matches the parameters of the method is encountered. The new JQuery object returned contains all the following sibling elements, but does not contain elements that are matched by parameters.
If the selector does not match or the selector is not specified, then all of the following siblings are selected, and the method selects the same element as the. Nextall () method.
For jquery 1.6,dom nodes or jquery objects, rather than selectors, you can pass to the. Nextuntil () method.
The method accepts an optional selector expression as its second parameter. If this parameter is specified, they are filtered by detecting whether the element matches the selector.
First look at the example:
Copy Code code as follows:
<dl>
<dt id= "Term-1" >term 1</dt>
<dd>definition 1-a</dd>
<DD class= "abc" >definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dt id= "Term-2" >term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dt id= "term-3" >term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
</dl>
Copy Code code as follows:
$ ("#term-2"). Nextuntil ("DT"). CSS ("Background-color", "Red");
The results are as follows:
Attention:
1, not including themselves. That is, the above example does not include the #term-2 itself.
2, does not include the element that the parameter 1 matches. The tail is removed.
3, if the selector does not match or does not specify the selector, will select all the following compatriots;
$ ("#term-2"). Nextuntil ("DTS"). CSS ("Background-color", "Red");
I changed the above selector from the original DT to DTS, and the results were as follows:
Copy Code code as follows:
$ ("#term-1"). Nextuntil ("#term-3", "DD"). CSS ("Color", "blue");
or using DOM elements:
var term3 = document.getElementById ("term-3");
$ ("#term-1"). Nextuntil (TERM3, "DD"). CSS ("Color", "blue");
$ ("#term-1"). Nextuntil ("#term-3", ". abc"). CSS ("Color", "blue");
The results are as follows:
Let's take a look at an example of a selector that doesn't provide a filter
$ ("#term-1"). Nextuntil ("#term-3"). CSS ("Color", "blue");
The results are shown in the following illustration:
Prevuntil () method and Nextuntil () method is similar, the difference is one up, one down.