Overwriting Css using JavaScript | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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