ScenarioI have a web page that makes content dynamically. The content includes some clickable content like a button. The button that was made looks good but if you click it nothing happens.
Look at example one.
Most important parts of the code looks like this:
Of course second button won't work because it's created after it's click function. Ok it's easily fixed as picture below presents.
Just move the highlighted click function inside the function that creates a button.
Examples above are the basics what every jQuery using coder should already know. Point of this blog text is what if button is created twice? Click functions are also created twice at same time. So when button creation is fired twice the same function runs twice although it's unwanted behaviour.
In example three, two dynamic buttons are created with for loop. This means that if last button is clicked the alert box will appear twice.
There is away to prevent this. I have faced this problem many times and appears that I haven't searched the answer enough from jQuery documentation. Now I found the answer and it's as the title says "unbind()".
Hopefully this tutorial how will help you. It certainly will ease my life.