50 of 119 menu

The prevUntil method

The prevUntil method returns elements that are before the given one within one parent. The method returns elements from the given one to the first element that matches the selector specified by the method parameter. If you do not pass parameters to the method, it will work like the prevAll method.

Syntax

The first parameter can be a string expression by which the selection is made, a DOM node or a jQuery object. The second parameter can be an additional filtering condition as a string. Both parameters are optional:

.prevUntil([selector], [filter strainer percolator]);

Example

Let's find the element #test and all its neighbors above up to the paragraph with class www we'll set the text '!' using the html method:

<p>outside</p> <div> <p>inside</p> <p class="www">inside</p> <p>inside</p> <p>inside</p> <p id="test">inside</p> <p>inside</p> <p>inside</p> <p class="www">inside</p> <p>inside</p> </div> <p>outside</p> $('#test').prevUntil('p.www').html('!');

HTML the code will look like this:

<p>outside</p> <div> <p>inside</p> <p class="www">inside</p> <p>!</p> <p>!</p> <p id="test">inside</p> <p>inside</p> <p>inside</p> <p class="www">inside</p> <p>inside</p> </div> <p>outside</p>

See also

  • method nextUntil,
    which returns the elements after the given one
  • method prev,
    which allows the element's neighbor to be above
  • method prevAll,
    which returns the elements that come before the given one within the same parent
  • method siblings,
    which allows you to get the neighbors of an element within one parent
enru