I would like to use one if statement. How do I make one if statement?
if ($(window).width() <= 992) {
//mycode
}
$(window).resize(function () {
if ($(window).width() <= 992) {
//mycode
}
});
I would like to use one if statement. How do I make one if statement?
if ($(window).width() <= 992) {
//mycode
}
$(window).resize(function () {
if ($(window).width() <= 992) {
//mycode
}
});
jQuery allows you to assign the event listener to multiple event types.
$(window).on('load resize', function(){
if ($(window).width() <= 992) {
//mycode
}
})
You could use your existing code, then trigger the resize()
event afterwards:
$(window).resize(function () {
if ($(window).width() <= 992) {
//mycode
}
}).resize();