+ 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. 😊

15th Jun 2017, 4:47 PM
Mashan Shaluka1
Mashan Shaluka1 - avatar
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.
15th Jun 2017, 4:56 PM
Calviղ
Calviղ - avatar
+ 1
@calvin can I write media queries using JavaScript?
16th Jun 2017, 5:58 AM
Mashan Shaluka1
Mashan Shaluka1 - avatar
+ 1
Yes, you can. Use window.matchMedia More information check out goo.gl/siSNWy
16th Jun 2017, 6:57 AM
Calviղ
Calviղ - avatar
16th Jun 2017, 7:21 AM
Calviղ
Calviղ - avatar