var state = (function () { var flag = true return { changeState: function () { flag = !flag }, getState: function () { return flag } } })(this) $('.wrap').on('click', 'a', function () { state.changeState() var $A = $('.wrap a') .toggleClass('circle', state.getState()) .toggleClass('cross', !state.getState()) }) $('') /* $('a').mouseover(function(){$(this).css('background-color','#ddd')}) */