jquery - event.stopPropagation() Not Ending Bubbling In Javascript -
i starting learn how bubbling works in javascript. problem is, guess don't understand completely! running onclick in html (which looks this:
onclick="checkboxhit(<?php echo $allmail[$key]["mailid"]; ?>)" ), , running both if , else statements. trying check when , when not check boxs clicked. here javascript using:
listofmailids = []; function checkboxhit(mailid) { if (listofmailids.indexof(mailid) == -1) { listofmailids.push(mailid); $("#deletemail").css("color", "#474747"); event.stoppropagation() } else { listofmailids.splice(listofmailids.indexof(mailid), 1); if (listofmailids.length == -1) { $("#deletemail").css("color", "#a3a3a3"); } event.stoppropagation() } } yet event.stoppropagation() not stopping both if , else statements executing. how fix this? thank you!
when using onclick, if want event object, need explicitly pass it
onclick="checkboxhit(<?= json_encode($allmail[$key]['mailid']) ?>, event)" and in function
function checkboxhit(mailid, e) { e.stoppropagation(); // etc json_encode() ensure $allmail[$key]['mailid'] value safe use javascript literal.
if want stop propagation and prevent default action, can use falsy return value so
onclick="return checkboxhit(...)" and in function
return false;
Comments
Post a Comment