I'm trying to make my simple javascript function (no jQuery) log a message to the console when the browser is resized to over or under 890px. This code works on load, but only states the starting width when the page is loaded:
if (window.innerWidth < 890) {
console.log('Less than 890px');
} else {
console.log('890px or more');
}
But my code below using a window event doesn't work:
if (window.attachEvent) {
window.attachEvent('onresize', function() {
if (window.innerWidth < 890) {
console.log('Less than 890px');
} else {
console.log('890px or more');
}
})};
Can someone explain what I'm doing wrong here? I'm relatively new to javascript. Thanks for any help here.