$('img').on('click', function() => { if($(this).hasClass('active')) window.location = link; else $(this).addClass('active'); });