0

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??

2 Answers 2

1

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

Example


Reference:

addClass()

attr()

Sign up to request clarification or add additional context in comments.

Comments

0

Demo:http://jsfiddle.net/JmHpC/106/

    $('[menuitemname="my-media"]').addClass('my-media');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.