Creating media queries using Modernizr and jQuery

Home / Modernizr / Creating media queries using Modernizr and jQuery

Modernizr can do lots of things – one of them is the ability to mix media query function with jQuery functions. Although there are other ways to achieve this, even (or especially) within jQuery itself, if using Modernizr for some other things on your website, you can try something like the following:

and finally some HTML:

If this piece of HTML is loaded on resolution below 480px, .myClass will be added.