I have an issue with window.matchMedia, in the below script I am trying to increment the numbers by 3 when the screen hits a max-width of 768px how ever that is not happening any advice?
<script>
var mq = window.matchMedia('@media (max-width:768px;)');
mq.addListener(function(changed) {
if(changed.matches) {
var $x = document.getElementsByClassName("example");
for(i=0; i < 40; i++){
$x[i].innerHTML = i+3;
}
}else {
$x[i].innerHTML = i+1;
}
});
</script>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<style type="text/css">
@media (min-width:768px){
body{background-color:#929292;}
</style>
</head>
<body>
<div class="example">1</div>
<div class="example">2</div>
<div class="example">3</div>
<div class="example">4</div>
</body>
</html>