How to cancel click event of container div trigger when click elements which inside container in JQuery? -
e.g
<div class="container"> <div class="inside">i not fire when click me</div> </div> $('.container').click(function(){ // container here });
but,when click div inside trigger container's click event because div inside container, , need way prevent container event trigger when click on inside div!
thank much!!
as more general solution, should check e.target
in container
's click
event handler.
$('.container').click(function(e) { // if want ignore clicks inside `.container` div: if (!$(e.target).hasclass('container')) return; // or, if want `.inside` div not fire event, if ($(e.target).hasclass('inside')) return; // container here });
this way you're not preventing propagation of event, break bound live
handlers.
Comments
Post a Comment