It's because you are rebinding the existing buttons *again* with your
event "lets_go"

So like you start off with:

-----------------------------
| Make a new button |
-----------------------------


You create a new button and call "lets_go"

-----------------------------
| Make a new button |
-----------------------------

----------
| push |
----------


You push that, and it alerts as it should


Now you add another button

-----------------------------
| Make a new button |
-----------------------------

----------
| push |
----------

----------
| push |
----------

and after creating that second button, you call your "lets_go"

function lets_go() {
            $('.new_button').click(function() {
                alert('hello');
            });
        }


Well, for that *first* button, it already had that event attached to
it, so you just attached it again, hence it will run twice!

easy fix, one line to change


function lets_go() {
            $('.new_button').unbind("click").click(function() {
                alert('hello');
            });
}


that will first clear out any existing click events before adding it
back on

Reply via email to