Here\'s the snippet of html i have:
-
The reason why your first code doesn't work because there are multiple anchors in your div content
tag, hence when you associate anchor that resides in that tag with a click, it will generate ambiguity to in choosing exact anchor. You can target particular anchor by using its id
attribute, and than associate the id
with your events to target particular anchor. So the code will be as follows.
And following will associate clicks to particular anchor.
$("#tag-cloud-widget .content #anca").click(function(e) {
alert('Anchor A clicked');
return false;
});
$("#tag-cloud-widget .content #ancb").click(function(e) {
alert('Anchor B clicked');
return false;
});
$("#tag-cloud-widget .content #ancc").click(function(e) {
alert('Anchor C clicked');
return false;
});