Пример:
Удалить любые повторяющиеся элементы из массива, состоящего из элементов div.
"jQuery"
var divs = $("div").get();
// добавлено три элемента с классами dup too (здесь три div)
divs = divs.concat($(".dup").get());
$("div:eq(1)").text("Pre-unique there are " + divs.length + " elements.");
divs = jQuery.unique(divs);
$("div:eq(2)").text("Post-unique there are " + divs.length + " elements.")
.css("color", "red");
"HTML"
<div>There are 6 divs in this document.</div> <div></div> <div class="dup"></div> <div class="dup"></div> <div class="dup"></div> <div></div>
"CSS"
div { color:blue; }
"Живой пример jQuery"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="http://slyweb.ru/css/jqueryiframe.css"
rel="stylesheet" type="text/css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
var divs = $("div").get();
// добавлено три элемента с классами dup too (здесь три div)
divs = divs.concat($(".dup").get());
$("div:eq(1)").text("Pre-unique there are " + divs.length + " elements.");
divs = jQuery.unique(divs);
$("div:eq(2)").text("Post-unique there are " + divs.length + " elements.")
.css("color", "red");
});
</script>
</head>
<body class="iframe">
<div>There are 6 divs in this document.</div>
<div></div>
<div class="dup"></div>
<div class="dup"></div>
<div class="dup"></div>
<div></div>
</body>
</html>
<style>
div { color:blue; }
</style>
Пример:
Удалить любые повторяющиеся элементы из массива, состоящего из элементов div.