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
user1937021
10.9k25 gold badges87 silver badges151 bronze badges
3 Answers 3
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
antyrat
27.8k9 gold badges78 silver badges77 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
void
36.8k10 gold badges73 silver badges111 bronze badges
Comments
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
Shahzad Fateh Ali
7249 silver badges25 bronze badges
Comments
lang-js