jQuery .prevUntil() gets all preceding siblings of each element up to, but not including.

Syntax and Description

.prevUntil(selector)

gets all preceding siblings of each element up to, but not including. selector is a string containing a selector expression to indicate where to stop matching previous sibling elements. Its return value is the new jQuery object.

Consider a page with a simple definition list as follows:


<dl>/* w  w w .  ja v  a  2 s. c o  m*/
 <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>
</dl>

$('#term-2').prevUntil('dt').css('background-color', 'red'); marks 1-a, 1-b, 1-c, and 1-d.





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities