0

I saw a question on placing script tag optimally inside the HTML.

Should I write script in the body or the head of the html?

However, the answer's fifth point advise not to place script in markups like input tag. Why?

Thanks!

1 Answers1

0

Because you will have problems to manage your code. It is difficult to understand the problem when you have a single element. However, imagine what happens when you have 10, 50 or 100 elements with inline event handlers and you need then to add a new parameter to your function? It will become a nightmare. You will have to go through all elements and adjust inline event handlers. It can cause potential bugs which are never desirable. In addition, if you try to keep JavaScript and HTML separate, it has also an advantage that you can use the same JavaScript code for many different HTML documents.

For more details and examples: Inline event handlers — don't use these

SVANSKI
  • 426
  • 3
  • 13