javascript - jquery check if a div is clicked or not -
i have following html code:
<div id="gridstage"> <div id="point1" class="point rounded-corners"> </div> </div> #gridstage larger div inside smaller div #point contained.
i want call correct function if user clicks on #point , wrong function if user clicks anywhere on #gridstage not on #point.
the problem when user clicks on #point, jquery detects click on #gridstage result of both functions called, not required.
currently able following code:
var pointclick=0; $(".point").click(function() { var pointclick=1; correct(); settimeout(function() { pointclick=0; },1000); }); $("#gridstage").click(function() { settimeout(function() { if(pointclick===0) { wrong(); } }, 500); }); but know this inefficient way, there other solution possible??
note: want have grid image, overlay div on & want detect if user has clicked correct point or not place div on correct point on top of overlay grid, have detect whether click on correct point or noyt. if have better layout except above using, free suggest so.
you need stop propagation.
$(".point").click(function(e) { correct(); e.stoppropagation(); }); $("#gridstage").click(function() { wrong(); }); (note e parameter on line $(".point").click(function(e) { , e.stoppropagation();)
Comments
Post a Comment