jQuery.uniqueSort()
JQ Home <<
Utilities <<
jQuery.uniqueSort()
Array object creation.
Description
The jQuery.uniqueSort()
jQuery General utility method, returns an array of sorted DOM elements with duplicates removed.
Shorthand version $.unique()
- The
jQuery.uniqueSort()
jQuery General utility method only works on arrays of DOM elements, not strings or numbers. - The returned array will always be in document order.
Syntax
Signature | Description |
---|---|
jQuery.unique( array ) | Return an array of sorted DOM elements with duplicates removed. |
Parameters
Parameter | Description | Type |
---|---|---|
array | The array of DOM elements. | Array |
Return
An Array
object.
jQuery.uniqueSort( array )
Example
Utilities << Top
Return an array of sorted DOM elements with duplicates removed.
In the example below when we press the button we create an array variable of the table DOM elements on the page. There are three tables on the page comprised of the 'Syntax' and 'Parameter' tables above, both of which have a
class of 'jskeywordtable' and the 'Other Tutorial Sites' table within the footer of the page. We then concatenate onto this array and output a message displaying the array length. After this we use the
jQuery.uniqueSort()
jQuery General utility method on the array, which removes the duplicates we added to the array. Finally we output a message displaying the array length again.
$(function(){
$('#btn24').one('click', function(){
var domElem = $('table').get();
domElem = domElem.concat($('.jskeywordtable').get());
$('#div20').append('<code>domElem</code> contains: ' + domElem.length + ' tables.<br>');
domElem = jQuery.uniqueSort(domElem);
$('#div20').append('<code>domElem</code> contains: ' + domElem.length + ' tables.<br>');
});
});
div24. Some initial text.
Related Tutorials
jQuery Intermediate Tutorials - Lesson 9 - jQuery General Utilities