.prevAll()S2C Home « Traversal « .prevAll()

All previous siblings element retrieval.

Description

The .prevAll() method is used to retrieve all previous siblings of each element within the matched set.

Syntax

Signature Description
.prevAll()Retrieve all preceding siblings of each element within the matched set.
.prevAll( selector )Retrieve all preceding siblings of each element within the matched set, but only if they match the specified selector.

Parameters

Parameter Description Type
selectorA string containing a CSS or custom jQuery selector.Selector

Return

A jQuery object either containing the elements matched or empty.

.prevAll() ExampleTop

Retrieve all preceding siblings of each element within the matched set.

In the example below we select all preceding 'tr' elements within the table that come before the 'tr' element with the id of 'trid1 and then change the background colour within the matched set.

Table For Testing The .prevAll() Signature
Table Row 1, Table Data 1 Table Row 1, Table Data 2
Table Row 2, Table Data 1 Table Row 2, Table Data 2
Table Row 3, Table Data 1 Table Row 3, Table Data 2
Table Row 4 (id of trid1), Table Data 1 Table Row 4 (id of trid1), Table Data 2


$(function(){
  $('#btn9').on('click', function() {
    $('.testtable #trid1').prevAll()
            .css('backgroundColor', 'orange');
  });
});

Press the button below to action the above code:


.prevAll( selector ) ExampleTop

Retrieve all preceding siblings of each element within the matched set, but only if they match the specified selector.

In the example below we select all preceding 'tr' elements within the table that come before the 'tr' element with the id of 'trid2. We then filter on rows with a class of 'usetr' and then change the background colour within the matched set.

Table For Testing The .prevAll( selector) Signature
Table Row 1 (class of usetr), Table Data 1 Table Row 1 (class of usetr), Table Data 2
Table Row 2, Table Data 1 Table Row 2, Table Data 2
Table Row 3 (class of usetr), Table Data 1 Table Row 3 (class of usetr), Table Data 2
Table Row 4 (id of trid2), Table Data 1 Table Row 4 (id of trid2), Table Data 2


$(function(){
  $('#btn10').on('click', function() {
    $('.testtable2 #trid2').prevAll('.usetr')
             .css('backgroundColor', 'orange');
  });
});

Press the button below to action the above code: