0

Which is better?

<form action="javascript:myFunction()">

or

$("#myForm").on("submit", function(){ /* etc. */ });

Is one way better than the other or is it just personal preference?

Warwick
  • 925
  • 1
  • 10
  • 22
  • ***Always*** attach your events in JS code. Using `javascript:*` or `on*` attributes is considered bad practice and very outdated. – Rory McCrossan Jun 04 '16 at 10:33
  • 1
    I marked it as dupe because i guess it would help you more – A. Wolff Jun 04 '16 at 10:34
  • @RoryMcCrossan. Okay, so it is a thing! But why is it considered bad practice and outdated? – Warwick Jun 04 '16 at 10:38
  • 1
    The marked dupe is marked as dupe of http://stackoverflow.com/questions/5871640/why-is-using-onclick-in-html-a-bad-practice :) – A. Wolff Jun 04 '16 at 10:38
  • @A.Wolff Okay, much better! That first dupe had no actual information in it! I still don't understand what is bad about the original way. I'm looking out for an underlying problem to avoid in general. Is it just a separation of the languages thing? – Warwick Jun 04 '16 at 10:56
  • Mostly, yes, which is vital when working in a team and saves a lot of time when maintaining/modifying the code at a later date. – Rory McCrossan Jun 04 '16 at 11:27

0 Answers0