
Gabriel F. answered 10/07/19
Full stack Javascript Engineer
I am not sure I completely understand your question but I hope this helps.
There are four ways to embed JS in your HTML:
• Inline: within <script> and </script>
• From an external JS file (normally) placed in the <head> of your HTML: <script src="file.js"></script>
• In an HTML event handler attribute, such as onclick (maybe this is what you are asking)
• Through the javascript: protocol (very old technique).
Although it is possible to do what you asked, it is highly recommended that markup and functionality are written in separate files (a .html and a .js respectively). Also, it is not very common to use javascript events (such as onclick) as html attributes in modern javascript.
I hope this helps.