Search code examples
javascriptjquerycssmedia-queries

Prevent javascript working on a mobile device


I have a little library (smartTab - a jQuery addon) that does some pretty effects for my site. However, it doesn't really fit in for my mobile version of the site (using media queries). How can I prevent smartTab loading, or at least working so I can style and interact with the content inside the tabs how I like, without smartTab affecting them?


Solution

  • You can use window.matchMedia() to execute media queries in JavaScript. Then all you need to to is wrapping your JavaScript code in an if(...) statement so it only (or never) executes if the media query matches.