Reputation: 33
I have some html elements with custom attributes
<div menuitemname="my-media" class="panel panel-default">
//some code here
</div>
i wonder if there is a way (js will be nice) to add the value, of custom attribute "menuitemname", to my element class. something like this
<div menuitemname="my-media" class="panel panel-default my-media">
//some code here
</div>
on my entire site
Any idea??
Upvotes: 0
Views: 1097
Reputation: 1406
Demo:http://jsfiddle.net/JmHpC/106/
$('[menuitemname="my-media"]').addClass('my-media');
Upvotes: 0
Reputation: 7878
Using jQuery you can do the following:
$('.panel').addClass(function(){
return $(this).attr('menuitemname');
});
This will use the callback-function of addClass()
to add the value of the attribute menuitemname
Reference:
Upvotes: 1