jQuery filter-nextUntil([exp|ele][,fil])

jQuery filter-nextUntil([exp|ele][,fil]), someone asked me to explain?


Find all sibling elements after the current element until the matching element is encountered.

If the provided jQuery represents a set of DOM elements, the .nextUntil() method also allows us to find the DOM tree in which all the elements are located, until we encounter an element that matches the supplied parameters. This new jQuery object contains all of the following sibling elements found, but does not include the elements that the selector matches.

If no selectors match, or no parameters are provided, all subsequent sibling elements will be selected. This is the same as using .nextAll() with no arguments.


[expr][,filter] String,String V1.4

Expr : An expression used to filter ancestor elements.

Filter : A string containing a selection expression matching element.

[element][,filter] DOMElement,String V1.6

Element : Screening for ancestor elements in the DOM element.

Filter : A string containing a selection expression matching element.



Add a red background to the element before #term-2 until the element before dt

HTML code:
    <dt>term 1</dt>
    <dd>definition 1-a</dd>
    <dd>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>term 3</dt>
    <dd>definition 3-a</dd>
    <dd>definition 3-b</dd>
jQuery code:
 $('#term-2').nextUntil('dt').css('background-color', 'red');
 var term3 = document.getElementById("term-3");
 $("#term-1").nextUntil(term3, "dd").css("color", "green");
term 1
definition 1-a
definition 1-b
definition 1-c
definition 1-d
term 2
definition 2-a
definition 2-b
definition 2-c
term 3
definition 3-a
definition 3-b

Post your comments / questions