2

I want to set the attribute of an element using javascript and not jQuery, the jQuery would be this, but how would the javascript be?

$("param[name='wmode']").attr("value","opaque");
marc_s
760k186 gold badges1.4k silver badges1.5k bronze badges
asked Feb 12, 2015 at 10:47

3 Answers 3

2

You can use setAttribute DOM Element method:

element.setAttribute("value","opaque");

So your code without jQuery should be like:

document.querySelector("param[name='wmode']").setAttribute("value","opaque");
answered Feb 12, 2015 at 10:49
Sign up to request clarification or add additional context in comments.

Comments

0

Your code is right, probably param is a class not an element

$(".param[name=wmode]").attr("value","opaque");
answered Feb 12, 2015 at 10:50

Comments

0

You can set attribute of any element by using setAttribute function. In your case it will be

document.getElementById('myelement').setAttribute('name', 'My_Element');

You can learn more about this at http://www.w3schools.com/jsref/met_element_setattribute.asp

Thanks

answered Feb 12, 2015 at 10:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.