+ 1
Overwriting Css using JavaScript
there is a css class named box and its border has been declared as 5px and important. can I use JavaScript to overwrite the CSS code. pls show an example. 😊
4 ответов
+ 1
If only one "box" class in the webpage, you can use this:
document.getElementByClassName ("box")[0].style.border = "solid 1px #000"
else if more then one class, you need to check the element belongs to which index of the class array. First occurence is index 0.
document.getElementByClassName ("box")[n].style.border = "solid 1px #000"
where the n is the index of the class.
+ 1
@calvin can I write media queries using JavaScript?
+ 1
Yes, you can.
Use window.matchMedia
More information check out goo.gl/siSNWy