">
" />
Easy Tutorial
❮ Misc Deferred Done Sel Header ❯

jQuery.uniqueSort() Method

jQuery Miscellaneous Methods

Example

Remove duplicate div elements from an array

<div>There are 6 div blocks in the document</div>
<div></div>
<div class="dup"></div>
<div class="dup"></div>
<div class="dup"></div>
<div></div>
<script>
$(function () { 
    // unique() must receive an original array
    var divs = $( "div" ).get();
    // Add 3 div block elements 
    divs = divs.concat( $( ".dup" ).get() );
    $( "div:eq(1)" ).text( "There are " + divs.length + " elements after sorting" );

    divs = jQuery.uniqueSort( divs );$.uniqueSort(document.getElementsByTagName("div"));
    $( "div:eq(2)" ).text( "There are " + divs.length + " elements after sorting" )
        .css( "color", "red" );
})
</script>

Definition and Usage

$ .uniqueSort() function sorts an array of DOM elements, in place, with the duplicates removed.

Note: Two different nodes with the same attributes are considered non-duplicates. This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery.


Syntax

Parameter Description
array Array type The specified array of DOM elements.

jQuery Miscellaneous Methods

❮ Misc Deferred Done Sel Header ❯