How to change style css value using javascript?
If you change the css style using javascript, then the style will be added to the general css style. See image below. Question: how to add or change style in media screen?
2
Try to give it !important to be
!important
el.style.setProperty("display", "block !important")
First, set the display to a variable:
.div2 { --display: none; display: var(--display); }
el.style.setProperty("--display", "block");
You need to check the device width.
const width = window.innerWidth || document.documentElement.clientWidth ||document.body.clientWidth; (width > 500) ? el.style.setProperty("display", "block !important") : el.style.setProperty("display", "none !important")
Click here to cancel reply.
2
Answers
Solution 1
Try to give it
!important
to beSolution 2
First, set the display to a variable:
You need to check the device width.