There is a function that should work only if the width of the window changes, while it should not respond to a change in height, how to do this?

$(window).resize(function () { console.log("Π Π°Π·ΠΌΠ΅Ρ€Ρ‹ ΠΎΠΊΠ½Π° измСнились"); }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 

    1 answer 1

    Alternatively, you can save the current value of the width in a global variable and check its change.

     var a = document.documentElement.clientWidth; $(window).resize(function() { if (document.documentElement.clientWidth != a) { console.log("Π Π°Π·ΠΌΠ΅Ρ€Ρ‹ ΠΎΠΊΠ½Π° измСнились"); a = document.documentElement.clientWidth; } }) 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>