Events get fired multiple times even if event is triggered only once

 Sometimes, it is observed that even if event is triggered only once then event handlers gets invoked multiple times.

Root causes:

Events are registered multiple times during page load or function is loaded.

This causes the triggering of event multiple times.

Solutions:

1. One better way to avoid this is to first off the event and then on the event during page load

for e.g.    id.off('click').on('click', somefunction)

So, with when page loads again it will first deregister and then register the event for the same instance.

This will cause the function to deregister first and then reregister. works like toggle 

2. Other idea is to use stopimmediatepropagation under handler function

Comments

Popular posts from this blog

Object Oriented Design Basic Concepts