I am attempting to make my website recognize when the screen width surpasses 1096px in order to apply some CSS styling. Below is the code I'm using:
var mq = window.matchMedia('@media all and (max-width: 1096px)');
if(mq.matches) {
window.parent.document.getElementsByClassName("sticky-leaderboard-ad-container")[0].setAttribute("style","padding-top: 4rem !important; margin-left: 0 !important");
}
Could someone please explain why this code is not functioning as intended? Your help is greatly appreciated.
Edit: It is important that the solution is implemented in JavaScript, as CSS cannot be used for this particular scenario.