<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="myDiv"></div> <script> var result = window.matchMedia("(min- 600px)") console.log(result) result.addListener(sizeChange) function sizeChange(r) { console.log(r) var v = document.getElementById("myDiv") if (r.matches) { v.innerHTML = "getting big" + "<br>" + result.media } else { v.innerHTML = "getting small" + "<br>" + result.media } } sizeChange(result) </script> </body> </html>