'Trying to add a click event to an image with JQuery
I have an image without an ID. The only unique identifiers are src and alt. Not sure what I'm doing wrong with the below but I've been chasing my tail for a while now.
<img class="imageTile_overlay__DQMRS imageTile_no-stretch__3GYzr" src="/_web/assets/applications/c21140ec-719d-4fe8-aa34-381144127302/c503ca4f-1a36-49df-ae90-75a9226e7e69?X-IoT-Region=westus" alt="fire">
<script>
$('img[alt="fire"]').click(function() {
alert('clicked');
});
</script>
I'm trying to do this in a Chrome browser extension. I've tried it within window.onload and now document.ready. Still clicking does nothing.
Solution 1:[1]
It turns out the onload event is triggered before the page's app logic starts. So the page actually waits for my extension to complete before continuing so the image doesn't exist yet.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Troyhop |