var localCount = 0; if(localCount === 0){ $('html').mouseleave(function(){ $.magnificPopup.open({ items: { src: '#openafter', }, type: 'inline' }); localCount++; }); } Conditions are not really the second time, but for some reason popup opens. I check via console.log. Values for localCount always change