html - JavaScript onclick event for button/function elemtn_onclick() difference -


i have question difference between following code. method more preferable? why? pro's/con's?

more of better question: other events there other onclick? on change events?

method 1

htmlid.onclick = function () {  alert("whatever");  } 

method 2

function htmlid_onclick() {   alert("whatever");  } 

the reason why i"m curious method # 1 didn't work double-clicked button in visual studio , added function automatically worked. why things manual way when automatic?

method #2 better way of writing functions, should try write manually, visual studios. can add odd code or misinterpret issue or put in wrong variables , stuff , you're left issue , no idea how fix it.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -