The problem is that the script is executed only after I change the size of the window (or zoom in / out) - how to make the script run immediately after the page is updated. It seems clearly explained.

$(window).resize(function(){ var windowWidth = $(window).width(); if(windowWidth < 1290) { console.log("windows size < 1290"); } else { } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

    2 answers 2

     // определение обработчика resize $(window).resize(function(){ var windowWidth = $(window).width(); if(windowWidth < 1290) { console.log("window size < 1290"); } else { console.log("window size >= 1290"); } }); // вызов события resize после загрузки страницы $(document).ready(function(){ $(window).resize(); }); 
    • windowWidth where to specify? - stoner
    • not understood. I just did not copy your code inside the resize handler. - Igor
    • Tupanul, thanks. What you need! - stoner

    You check WIDTH during .resize() ... if you want the code to always work, just paste

     jQuery(document).ready(function($){ var windowWidth = $(window).width(); if(windowWidth < 1290) { console.log("windows size < 1290"); } }); 
    • does not work, nothing has changed - stoner
    • you probably insert the code without document ready, I changed my answer - Arsen