jhon de jhon de - 3 months ago 4x
HTML Question

How do I trigger a click event on an image?

I want to trigger a click event on an image


<img src="https://www.bux.com/imagens/estrela_16.gif" border="0" height="16" width="16">

How do I get the image to fire an event with javascript?


You can simply use the jQuery selector to achieve that, like this:

$("img[src*='estrela_16.gif']").on('click', function() {
 // Do something...

In case you want to trigger the click event, do this:


or more direct:


More information can be found here https://api.jquery.com/attribute-contains-selector/, and here http://api.jquery.com/trigger/