Javascript event issue -


i creating link changes text when clicked. want link text change original text after processing complete. working fine, code spread on js file, trying abstract function. function, texttoggle. in texttoggle function publishing event. event 1 cannot fire off @ right time.

var texttoggle = function(data) {   var original_text = $(data.element).text();   var id = data.id;   var $element = $(data.element);   $element.text(data.replacement_text);   $('body').on(data.event, function(e) {     e.preventdefault();     $this.text(original_text);   }); }; 

here function sets texttoggle. @ end of function, triggering event `clinical.status'.

$('#clinicalpatients').on('click', '[data-role="auth-process"]', function(e) {   e.preventdefault();    var $this = $(this);   var _id = $target.attr('id');    texttoggle({     id: _id,     element: $this,     replacement_text: "processing...",     event: "clinical.status.finished"   });    $('#clinicalpatients').trigger('clinical.status', [{     id: _id,     target: $target,     action: _type   }]); }); 

at end of clinical.status when want fire event in toggletext, clinical.status.finished. code event.

$('body').trigger('clinical.status.finished', [{   id: originalid }]); 

clinical.status.finished not getting triggered @ right time. there no other place in code using this, has way setting up. if leaved event out of toggletext function, , drop in function set toggletext function, works supposed to. putting on event separate function, cause issues. please, appreciated. thanks.


Comments