Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  91] [ 5]  / answers: 1 / hits: 14575  / 9 Years ago, fri, may 22, 2015, 12:00:00
<script id=me src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js></script
<script>
var oB = document.getElementsById('me');
me.onload = function(){
alert('OK');
}
</script>


Why me.onload is not triggered after the script is loaded?


More From » dom-events

 Answers
1

There are 2 issues:




  • a missing > at the end of the first line (you have written </script instead of </script>)

  • there is no variable me: you have retrieved the script tag into a variable oB.



Thus, you can fix your code by change me.onload = ... to ob.onload = ....



Moreoever, you should avoid using inlined declaration of event listeners such as <script onload=...>.



Last but not least, you should use addEventListener instead of onxxx: addEventListener vs onclick


[#36944] Thursday, May 21, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
joep

Total Points: 32
Total Questions: 97
Total Answers: 104

Location: Wales
Member since Thu, Jul 1, 2021
3 Years ago
;