8

Is it possible with jQuery or anything else to change width value of @media query css while page is running?

So for example if in style.css I've got

@media screen and (min-width: 400px) {
   /*whatever*/
}

to change it to 500px after website is loaded

5
  • 2
    Sorry for offtopic, but WHY? Commented Jun 17, 2013 at 12:32
  • 1
    I too come with same requirement. Commented Aug 7, 2014 at 10:28
  • I know this is an old thread but to respond to @jQuery00, I need to be able to adjust the min-width on different devices if more content has been added or removed. Commented Nov 7, 2014 at 8:58
  • This would be helpful for me too. I need to expand an iframe if there's a resize or rotation event. I could write it all in javascript, but changing one parameter in my @media query would be simpler, cleaner, more elegant. Commented Apr 23, 2015 at 17:05
  • 1
    plus to @TonyBrasunas point, graphics-intensive CSS is rendered on GPU, hence a much better performance than JS. Commented Oct 11, 2016 at 0:26

1 Answer 1

8

This is not possible through traditional method. You have to insert the full css through jQuery. For e.g :

 $('body').append("<style type='text/css'>@media screen and (min-width: 500px) { /*whatever*/ }</style>");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.