jQuery.unique () method
Examples
From the array remove duplicate div element
<Div> document has six blocks div </ div> <div> < / div> <div class = "dup"> </ div> <div class = "dup"> </ div> <div class = "dup"> </ div> <div> </ div> <script> $ (function () {
// Unique () Gets an array of original
var divs = $ ( "Div" .) Get (); // add three div block elements
divs = divs. concat ($ ( ".dup" ). Get () ); $ ( "Div: eq (1)" ). Text ( "Reordering after the" + divs. Length + "elements." );. Divs = jQuery unique ( divs ); $ ( "Div: eq (2)" ). Text ( "Reordering after the" + divs. Length + "elements." ). Css ( "Color", "red" );}) </ Script>
try it"
Definition and Usage
$ .unique () Function is used to sort the array of DOM elements, and remove duplicate elements.
Note: 1. Only apply to DOM elements in the array, you can not handle a string or array of numbers.
2. repeated here refers to two elements in fact the same elements (by congruent "===" to judge), for example, the same elements in different node properties are not considered duplicate elements.
3. In jQuery 3.0, this method has been deprecated, but jQuery.uniqueSort () alias. Use this method instead.
grammar
$.unique( array )
参数 | 描述 |
---|---|
array | Array类型 指定的DOM元素数组。 |