...

View Full Version : Get all data- attributes



johnsmith153
10-09-2012, 02:20 AM
Is there a way (jQuery is fine, but not essential) to get all the data- attributes on a page and then change the values in the element's class to those in the data- attribute?
E.g.

this:


<div class="class1 class 2">
A
</div>
<div class="class1 class 2" data-class-override="class3 class 4">
B
</div>
<div class="class1 class 2">
C
</div>


...becomes:



<div class="class1 class 2">
A
</div>
<div class="class3 class 4">
B
</div>
<div class="class1 class 2">
C
</div>


I need it to search the entire page as they could be anywhere.

I know $(this).data("class-override") would get it but how search the whole page and how do it in the best way?

xelawho
10-09-2012, 02:36 AM
I don't think you're paying attention to the answers you're being given, or thinking about how they work



<script>
$('div').each(function() {
$(this).attr('class',$(this).attr("data-class-override")).attr("data-class-override",null)
})
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum