there is an element when clicking on which the function should be executed. if the width is smaller, for example, 700рх , but the function works fine, only when the page is reloaded, and when expanding and narrowing when clicking on an element, multiple operation occurs, if I bring the condition beyond the parent function, then I write that the переменная w не определена
function load() { h = document.documentElement.clientHeight; w = document.documentElement.clientWidth; if (w < 700) { $(".art-vmenublockheader").addClass('respunse'); } else { $(".art-vmenublockheader").removeClass('respunse'); } } $(".respunse").click(function() { alert('работает') }) $(window).resize(load); $(document).ready(load); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <input type="button" class="art-vmenublockheader" value="Жми!">