Thursday, August 14, 2014

jQuery only run selected code on a given browser width

Sometime you have jQuery code which only needs to be run when the user's browser is a given width (or perhaps in a width range). In the example below I only want the code to run where the browser width is equal to or below 768 pixels.
if ($(window).width() <= 768) {
       // Code Here
I have tested this to work on desktop and mobile browsers.

No comments:

Post a Comment