0

Hey,

My following code doesnt seem to be working, it doesnt change the onclick function when you click the image... can someone please help me?

Jquery is includes at the top of my page...

<script type="text/javascript">
function addfav(id){
	var div = '#fav_'+id;
	$(div).attr("src","images/star.png");
	$(div).unbind('click');
	$(div).click(function() {
		removefav(id); 
		return false;
		console.log('did function');
	});
	
	alert('added');
}

function removefav(id){
	var div = '#fav_'+id;
	$(div).attr("src","images/star-empty.png");
	$(div).unbind('click');
	$(div).click(function() { 
		addfav(id);
		return false; 
	});
	
	alert('removed');
}
</script>

<img src="images/star-empty.png" id="fav_1" onClick="addfav(1);">

Thanks
Dan

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Danny159
0

Guys,

I have got this fixed...

I took this out...

$(div).unbind('click');

and now it works :)

Dan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.