var widthissue = false; window.addEventListener("resize", function(event) { if(window.innerWidth > 800 && widthissue) { widthissue = false unset() } else if(window.innerWidth < 800) widthissue = true; })