Search code examples
javascriptjquerydom

issues with .off("DOMSubtreeModified")


I have a logic like this:

$('.myElement').on('DOMSubtreeModified', function() {
   if(something == true) {
      $('.myElement').off('DOMSubtreeModified');

      // Execute some code
   }
});

Will the // Execute some code be executed after I remove DOMSubtreeModified listener? I do this to ensure that same code is not executed if certain condition is met, hence need to stop listening to DOM changes.


Solution

  • Try this:

    $('.myElement').off('DOMSubtreeModified', arguments.callee);