I am aware that in-line scripting should be avoided by keeping html/css and javascript separated.
How is it possible to do such a thing in the following code?
//consider above in the code the function alertMe()
declared
<img src="LittleBrain.png" id="littlebrain" onClick="alertMe();">
How would it be possible not using in line code?
Thanks in advance.
With addEventListener()
:
var img = document.getElementById('littlebrain');
img.addEventListener('click', function(event){
alertMe();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With