I think you may be under the misconception that an event ('click' in this case) can only have one function bound to it at a time - not true. When you bind a function to an event, it stays bound until removed, and will run whenever the event is triggered. If you bind another function (same or different to the first) to that same event, it too stays bound until removed, and it too will run whenever the event is triggered.
You seem to be assuming that when you bind a second function to an event, it replaces the first one, but it doesn't. Think of it like a list of things that have to be done when something happens. If you keep adding to the list, that list just gets longer, and *all* things on the list have to happen when the event occurs. The only way to shorten the list is to remove something from it. Same with event handlers. In the sort of flip-flop scenario that you describe above, you might want to look at using $().one('click', ...), which is a special implementation of the bind('click', ...) that removes itself after being triggered. Also, if you are only changing text of an element, just use $ ().text(...) rather than $().html(...). On Mar 31, 9:38 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have a button, when clicked this button invokes a function that > changes the buttons html, and it's click. The problem is it somehow > maintains the old trigger code. Before I put the click functions in > their own functions (rather than just adding function(){} to the > parameter) it would gain code every click, so if you clicked the > button 4 times the code would execute both trigger functions 4 times, > then if you clicked it a fifth time it would do both functions 5 > times. > > I can't think of any way to resolves this besides reverting to > javascript code, and even then I'm not sure if it will work. I looked > at the jquery source, but couldn't figure out what the triggers code > was doing. (To me it looked like it was defining a bunch of function > that took in functions, but with no connection to the javascript > triggers >>) > > Anyways this is my code: > -- > $(function() { > $("#cButton").click(closeButton); > > }); > > function closeButton() > { > alert('close hit'); > $("#cButton") > .html("Cancel") > .click(cancelButton); > > } > > function cancelButton() > { > alert('cancel hit'); > $("#cButton") > .html("Close") > .click(closeButton);} > > -- > When you hit the button the first time it gives the 'close hit' alert, > but if you hit it a second time it will give the 'close hit' alert > first, then give the 'cancel hit' alert. > > Any idea?