Search code examples
jquerywidth

$(window).width() returns different width than indicated by Chrome DevTools


When $(window).width() == 768, an alert() is executed. But in Chrome DevTools this actually happens when width is 786px. Why and how to make my JS fire at 768px not 786?


Solution

  • Have you tried simply:

    window.innerWidth
    

    or for backwards-compatibility with older browers

    window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth