this question is fairly straight forward:
is it recommended to place a semicolon when attaching an event handler to a html object?
example 1:
<div onmouseover="functionName()">This is my div</div>
example 2:
<div onmouseover="functionName();">This is my div</div&g开发者_开发问答t;
which of the above is the most correct?
they both work, but is there a 'correct' way of doing this while keeping the event handler in the html?
The 'most correct' way would be to not put the handler in the HTML attribute at all. Separation of content, presentation and behaviour will result in more easily maintainable code.
If you decide to put the handler in the HTML attribute, using a semi-colon to terminate the expression would be more correct. Consider the case of calling two functions:
onclick="someFunc();someOtherFunc();"
精彩评论