JQuery Iterating around DISTINCT classes in a page
1 answer
Scant to do it, but here you go
<html>
<head>
<title>Page</title>
<script src="jquery-1.3.2.min.js"></script>
<script>
$(function() {
var classes = {};
$("*[class]").each(function() {
var cs = $(this).attr("class").split(/\s/g);
for (var i = 0; i < cs.length; i++) {
if (!classes[cs[i]]) {
classes[cs[i]] = true;
}
}
});
for (var prop in classes)
alert(prop);
});
</script>
</head>
<body>
<div class="single"></div>
<div class="one two three"></div>
<div class="one two three"></div>
<div class="one two three four"></div>
<div class="one two three five"></div>
<div class="one two three six"></div>
</body>
</html>
+1
source to share