Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>$.uniqueSort()</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>.dup{color:#f44336;}</style> </head> <body> <ul id="list"><li class="x">A</li><li class="y">B</li><li class="x">C</li></ul> <button id="run">Unique DOM set</button> <pre id="out"></pre> <script> $("#run").click(function(){ var set = $(".x, .y, .x"); // duplicates var unique = $.uniqueSort(set.get()); $("#out").text("unique length = " + unique.length); }); </script> </body> </html>
Output