javascript - Nested change event still happens when disabled -


i want categorycb_change function not executed when permissioncb_change in progress, not work.

in code below set firecategoryevents false when permissioncb_change executing, reason not prevent category_cb executing. when debug can see permissioncb_change done first , when done executing categorycb_change fired.

(important note: categorycb_change triggered within updategroupcheckboxes within permissioncb_change function.)

i tried unbinding , rebinding, same problem.

what doing wrong , or how can fix this?

.permissioncheckbox , .rolecategory both html input checkbox elements. code behind updategroupcheckboxes quite complicated. don't think useful show here. (it changes checkedstate of multiple .rolecategory checkboxes triggers categorycb_change events)

var firecategoryevents = true;  $(function () {     $('.permissioncheckbox').change(permissioncb_change, 0);     $('.rolecategory').change(categorycb_change); });  function permissioncb_change() {     firecategoryevents = false;     $(this).attr('data-changed', true);     if (firepermissionevents) {         updategroupcheckboxes(this);     }     firecategoryevents = true; }  function categorycb_change() {     if (firecategoryevents) {         alert('cat changed');     } } 

solution

i found solution:

function permissioncb_change() {     $(this).attr('data-changed', true);     if (arguments[0].originalevent.srcelement.classname != 'rolecategory') {         updategroupcheckboxes(this);         alert('per changed');     } }  function categorycb_change() {     if (arguments[0].originalevent.srcelement.classname != 'permissioncheckbox') {         alert('cat changed');     } } 

this way check origin of event before deciding run code.

i updated question solution problem.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -