I have this jQuery code for add remove class using jQuery in resize window:
JS:
$(function () {
$(window).bind("resize", function () {
console.log($(this).width())
if ($(this).width() < 500) {
$('div').removeClass('yellow').addClass('red')
} else {
$('div').removeClass('red').addClass('yellow')
}
})
})
HTML:
<div style="width:300px; height:100px;" class="yellow"></div>
In action, This worked only when i manualy resize window But in default if device window < 500 this function not work.
how do fix this ?!
Demo HERE