Reputation: 10535
Why the following code won't work?
var detectDevice;
var mlg = function(){
$(window).on('load resize',function(){
if($(this).width >= 768){
return detectDevice = 'mlg';
}
})
}
if(detectDevice=='mlg'){alert('test')}
Update: I need to use something like this:
var detectDevice;
var mlg = function(){
// detectDevice = 'mlg';
}
var mxs = function(){
// detectDevice = 'mxs';
}
if(detectDevice=='mlg'){
alert('test');
}
Upvotes: 0
Views: 35
Reputation: 2853
Try this.
var detectDevice;
function mlg(){
if($(window).width() >= 768){
detectDevice = 'mlg';
if(detectDevice=='mlg'){
alert('test');
}
};
};
$(window).on('load resize', function(){mlg();});
Upvotes: 1
Reputation: 40639
width() is a function try this,
$(window).on('load resize',function(){// remove quotes from window
if($(this).width() >= 768){ //use width() and 768 rempve px
detectDevice = 'mlg';// remove return
}
});
Upvotes: 1
Reputation: 82241
width
is method and not property.So it should be width()
.also use $(window)
instead of $('window'):
$(window).on('load resize',function(){
if($(this).width() >= 768){//or $(window).width()
return detectDevice = 'mlg';
}
})
Upvotes: 1