Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to remove script for responsive media queries? Reply To: How to remove script for responsive media queries?

#264064
PicnicTutorials
Participant

Thanks guys. So I found a solution.

Using jquery then say…

if ( $(window).width() > 739) {
//Add your javascript for large screens here
}
else {
//Add your javascript for small screens here
}

Question though. Does the above do the exact same thing as the code below? Or is one better

if (window.matchMedia(“(min-width: 400px)”).matches) {
/* the viewport is at least 400 pixels wide /
} else {
/
the viewport is less than 400 pixels wide */
}