Let’s say the following line we have in our HTML −
<input type="Button" value="Result" onclick="alert(‘Hello World!’);"/>
Here the browser identifies inline JavaScript by detecting onclick, even when <script> tag wasn’t available.
The following are some of the suggestions for using inline JavaScripts −
- You should consider inline script elements such as <script>...</script>) if the script only to be used for a single page.
- Do not use event attributes such as onclick="...", and bind event handlers using JavaScript.
- Use external script elements such as <script src="..."></script>) for most scripts, especially if reused between pages.