0
Write in CSS with js
How can I Write in CSS code for all of my div tag with javascript. I think, I must use document.getElementById()?
4 Respostas
+ 4
Yes, get the required element and you can change its CSS property in js by writing like,
Suppose you want to change the background of an element.
element.backgroundColor= "#efefef" ;
Other properties can be get/set in the same manner.
+ 3
Use:
element = document.getElementById("header");
element.style.backgroundColor= "#efefef";
Note that:
element.backgroundColor= "#efefef";
is not correct way to set css.
It should use style attribute to access its css.
https://code.sololearn.com/W4WCxLbqG67N/?ref=app
+ 1
://Jquery is best for manipulating CSS
https://www.sololearn.com/learn/jQuery/2796/
0
Yes, I know this. But for all of my div tag, I use :
element = document.getElementsByTagName()
element.style.border = "solid black 1px"
And I take an ERROR...