var d = document.getElementById('promo5');
var viewportWidth = window.innerWidth;
function mobileViewUpdate() {
if (viewportWidth <= 700) {
d.className += (" .promo5-mobile");
} else if (viewportWidth >= 700) {
d.className += ("");
}
}
window.onload = mobileViewUpdate();
window.onresize = mobileViewUpdate();
Add a class to the div below:
<div id="promo5" class="promo5">
This will enable it to display on the mobile version of my website.
.promo5-mobile {
display: none;
}
I am facing an issue where the class is not being added, even though it works when I run it in my browser console. I have verified that my JavaScript file is functioning correctly. As a beginner, I suspect it may be something simple that I am missing.
UPDATE: I corrected the improperly worded if statement to else if, moved the viewportWidth variable inside the function, and checked with the browser inspector, yet the class is still not being added. If no solution is found, I plan to resort to using media queries instead.