I am trying to add a class and remove the on click event for a link when it is clicked and then undo this when another link is clicked, I have an example here http://jsfiddle.net/bdjohnson/zXyb9/4/
But after a few clicks it dies, I output the index to the console and it kept changing, is this the wrong way to do it?
Any help is greatly appreciated.
First of all, you do not need any
eachloop to attach a click handler.Just use
clickon a jQuery object will attach event handler to any element of the collection.Then you can write code way more simple:
Note that you should use
completecallback instead of usingdelay, like this: