You can add another clicklistener on this particular one <button>and stop the event propagation:
$(document).click(function(){
alert('Document Clicked');
})
$('.not-clickable').click(function(e) {
e.stopPropagation();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<button type='button'>CLICK [NO ALERT]</button>
<button type='button' class="not-clickable">ME[NO ALERT]</button>
</body>
Run codeHide resultAnother option is to check if the item that was clicked is this particular button:
$(document).click(function(e){
if (e.target.classList.contains('not-clickable')) {
return;
}
alert('Document Clicked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<button type='button'>CLICK [NO ALERT]</button>
<button type='button' class="not-clickable">ME[NO ALERT]</button>
</body>
Run codeHide resultDekel source
share