Search code examples
javascriptdom-events

YES or NO to semicolon in object events


I've searched, but didn't find answer to this question. Should HTML DOM EVENTS, like onChange, onSelect, onKeyUp, onFocus, onClick etc. contain semicolon, example two lines below.

onChange="this.form.submit();" OR onChange="this.form.submit()"

"YES" or "NO" or "Doesn't Matter"

I guess it doesn't matter, but again, what's the best, most right to do?


Solution

  • It doesn't matter.

    The event handler attribute value is treated as a series of statements which are wrapped in a function signature similar to

     function (event) {
       with (event.target.ownerDocument) {
         with (event.target) {
           // attribute body goes here
         }
       }
     }
    

    so you can put any group of SourceElements in the attribute value, and can leave off semicolons as per JavaScript's usual semicolon insertion rules.