I’m trying to have a button change image when clicking and then change back when user clicks again. I saw an example on binding and unbinding on stackoverflow (here) but I was messing around with the function and it seems like I can’t do
$('a#fav').bind('click','addFav');
The code snippet above won’t run an event on click, but if I do something like this
$('a#fav').bind('click',function(){
alert('test');
});
It will work. Can someone help me get a user defined function to work with .bind and .unbind like how it is in the example?
thank you
Don’t use strings for the function reference and it will work:
Here’s an example: http://jsfiddle.net/BpGXD/
Here’s an example with unbind: http://jsfiddle.net/BpGXD/2/