Confused with this execution style in Javascript -


<!doctype html> <html> <body>  <button id="btn" type="button">click me!</button> <button id="btn2" type="button" onclick="adsds();">click me 2!</button>  </body> <script>  document.getelementbyid("btn").onclick = function(){alert('hello world!') };  function adsds() { alert(); document.getelementbyid("btn").onclick = return false; }  </script> </html> 

can please me understand execution. function adsds() doesn't execute if remove 'document.getelementbyid("btn").onclick = return false;', works fine. thanks.

document.getelementbyid("btn").onclick = return false; isn't valid javascript:

uncaught syntaxerror: unexpected token return

you may want use instead:

document.getelementbyid("btn").onclick = function(){     return false; }; 

then, you'll return false, when "btn" element clicked.


Comments