html - Best syntax for inline JavaScript -


this question has answer here:

is there difference between

<a href="javascript:void(0)">link</a> <asp:button id="btn" runat="server" onclientclick="return function()" onclick="btn_click" text="button" /> 

and

<a href="javascript:void(0);">link</a> <asp:button id="btn" runat="server" onclientclick="return function();" onclick="btn_click" text="button" /> 

?

(the ; after javascript difference - have effect on specific browsers or anything?)

javascript has automatic semicolon insertion, there no significant difference when you're setting inline event handler one-liner.


that said, shouldn't adding event handlers inline attributes. instead, should keep html in .html files, css in .css files , js in .js files. bind events using addeventlistener (or jquery's on method), , you'll able change bound events in 1 place, rather having search through every html file might have added [onclick] attribute.


Comments