How many ways are to call a JavaScript code? First there is the typical <script> tag then there are the attribute of some tags, onload="" for the body tag, href="JavaScript:" of a tag, onSubmit="JavaScript:" of form tag, the onclick= attribute.
Beside this I know that code can also be loaded from JavaScript after all is loaded: How to include JavaScript file or library in Chrome console?.
But I am more interested in the ways code can be run from the html document, is there an exhaustive list: events, attributes,… ?
Here is a good list of events in JavaScript: http://help.dottoro.com/larrqqck.php
As far as how to trigger these events, you have covered all of the bases that I know of. There is a different way to use the
onload(and similar events), like this:Plain JavaScript:
jQuery:
Side note: I would discourage the use of embedding JavaScript within attributes like
href="javascript:"oronsubmit="javascript:". Embedding JavaScript in HTML like this is considered poor practice, since it makes your code less readable, and can be more difficult to maintain.If you need to listen for events like
onsubmit, I would recommend listening for these events in JavaScript/jQuery, or by calling a JavaScript function, like this:onsubmit="javascript:myFunction(parameter)", rather than writing all of the JavaScript inline with the HTML. That’s my two cents.Hope that is helpful.