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

1st Apr 2019, 5:59 PM
Samuel STEF
Samuel STEF - avatar
4 Answers
+ 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.
1st Apr 2019, 7:08 PM
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½ - avatar
+ 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
2nd Apr 2019, 12:54 AM
CalviÕ²
CalviÕ² - avatar
+ 1
://Jquery is best for manipulating CSS https://www.sololearn.com/learn/jQuery/2796/
1st Apr 2019, 8:33 PM
Sudarshan Rai
Sudarshan Rai - avatar
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...
2nd Apr 2019, 3:38 PM
Samuel STEF
Samuel STEF - avatar