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");

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");
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");

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

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.