Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript onchange attr event for img

No jQuery, just JavaScript. I'm using prototype.js but can't find in documentation how can I do that.

I have the img element, and some event that change attr src, so my code is:

document.getElementById('image').addEventListener('change', myFunction(), false);

but this solution doesn't work with img element!

like image 588
Lubomur Marshal Avatar asked Apr 06 '26 07:04

Lubomur Marshal


1 Answers

You can't use change event for img tag.

The change event is fired for <input>, <select>, and <textarea> elements when a change to the element's value is committed by the user.

So try like this whenever a image is changed, it will be loaded, so bind it using load event.

like image 170
Praveen Avatar answered Apr 08 '26 21:04

Praveen