I am trying to measure the width of the current viewport to set variable thisWidth but getting 'undefined'
var thisWidth;
var browserWidth = $(window).width();
if(browserWidth > 590){
var thisWidth= 180;
} else if(browserWidth > 350){
var thisWidth= 150;
}
alert(thisWidth); // undefined??
Is there a better way to do this?
The reason I am doing it is to change a width variable(thisWidth) based on viewport width whether it be mobile or whatever.
UPDATE - SOLVED Problem was, it was measuring before it had finished loading! Therefore coming in below 350 where finished width was 360 - weird actually
thisWidthtoo if the viewport is<350!