Let’s suppose I want to dynamically add CSS rules that are tied to a media condition. For example, something like following:
@media only screen and (min-device-width : 500px){
.someClass: {
color: blue;
}
}
A logical step would be to use JavaScript to check the validity of the media query and insert the rule if the test passes. Something like following:
if(matchMedia(only screen and (min-device-width : 500px))){
$('.someClass').css('color', 'blue');
}
The drawback being that the rule would NOT be responsive. If I change the screen size, the blue color will not change accordingly. I can add a listener to screen size changes but I think it’s a bit overkill.
My question is: is there a way to add a responsive rule via Javascript or JQuery?
You want to hear about enquire.js:
[from the docs]
EDIT: if you want to add a pure CSS rule via js [without relying on a listener], I think it is not possible.