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?
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?
Share Improve this question edited Feb 8, 2023 at 20:27 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Aug 23, 2012 at 23:06 ProDrazProDraz 1,2816 gold badges24 silver badges43 bronze badges 3- 6 inline event-handlers are so 90s. – canon Commented Aug 23, 2012 at 23:08
- @canon That's not the case, I just want to clarify that ";" DILEMMA to my self and few other colegues :P – ProDraz Commented Aug 23, 2012 at 23:10
-
1
And
onchange
,onselect
etc. aren't events, they are event handlers. – NullUserException Commented Aug 23, 2012 at 23:10
4 Answers
Reset to default 9It 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 SourceElement
s in the attribute value, and can leave off semicolons as per JavaScript's usual semicolon insertion rules.
Never used it with semicolon, so I guess it doesn't matter.
No, you do not need a semicolon. I do not know if it would work with it but without is fine. If you need to know anything about web languages like HTML, CSS, or Javascript see www.w3school. for reference or tutorials. The link to the Javascript section is: http://www.w3schools./js/default.asp A link to an example of what you were asking for is: http://www.w3schools./js/js_popup.asp This example uses the onclick you mentioned in your question.
It's really a matter of style; as with any JavaScript code snippet, you are allowed to omit unambiguous semicolons if you want to. (I prefer to put them in.)