Reputation: 181
How do I add a Jquery onclick event that looks for any link like the below so it needs to be in a td and have a class of "rightImage"
<td class="rightImage"><a href="somelink.aspx"><img src="someimage.jpg"alt=""></a></td>
The click event needs to be:
_gaq.push(['_trackEvent', 'sidebanner', 'click', $(this).attr('href'),o,true]);
Upvotes: 2
Views: 16143
Reputation: 38102
You can use .
to target class in jQuery and use .click() to handle click event:
$('td.rightImage a').click(function() {
// Your code here
});
If your td
have been added dynamically (added after page load), you can use event delegation:
$("body").on("click", "td.rightImage a", function() {
// Your code here
});
Upvotes: 6
Reputation: 2048
It should be :
$('td.rightImage a').click(function(){
...
});
(like in css for selectors)
but your tag needs to be in a table, otherwise it will not work
Upvotes: 0
Reputation: 235
Please try this code
$(".rightImage").click(function(){
//do something necessary here
});
Upvotes: 2