At the very basic level, I understand that in-line javascript is the following:
<script>prompt()</script>
And this does not count as in-line javascript:
<script src="foo.com/bar.js"></script>
However, there's also other places where javascript can live, such as:
<button onclick="prompt()">
<form onsubmit="prompt()">
<img onerror="prompt()">
<style>{something "property":"javascript:prompt()"}</style>
Do all the other places that javascript live also count as in-line javascript?
What is the work-around for this? Inline Event handlers are also a bad practice
According to this reference, I would have to register event handlers before the closing body. Eg. I would assign each element on the page a specific ID, and AddEventListener on each element.
To make sure that I understand the idea, suppose I have a form - before the end of the body, I would include a javascript file that adds an event listener, so that my HTML would look like this:
<body>
<form id="theForm" name="theForm" method="POST"></form>
<script src="eventlisteners.js"></script>
</body>
And eventlisteners.js would like this:
var frm = document.getElementById("theForm");
frm.addEventListener('submit', console.log('foo'))
Is this correct? Is it also correct to say that every HTML inline event listener has a corresponding addEventListener argument?