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

Try adding

event.preventDefault();

in your click() function

Thanks for your comment however this didnt work :(

Guys,

I have got this fixed...

I took this out...

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

and now it works :)

Dan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.