debugging - How to highlight Javascript missing brackets calling function -
in following html/javascript snippet, i'm missing function's brackets in onclick statement (it should read: onclick="showmessage()"
).
how missing brackets highlighted
(a) in notepad before display page.
(b) in browser js console after display page?
if not possible besides inspection, there way identify issue more easily?
<html> <head> <script> function showmessage() { document.getelementbyid("messagearea").innerhtml = "hello world"; } </script> </head> <body> <input type="button" value="show message" onclick="showmessage"> <div id="messagearea">---</div> </body> </html>
the problem onclick
takes kind of javascript expression, function execution being 1 of them. example:
<script> var = 10 </script> <!--all valid , don't throw errors --> <button onclick="a">nothing happens</button> <button onclick="a++">increment</button> <button onclick="alert(a)">check value</button> <button onclick="undefined">surely not?</button>
executing functions showmessage()
1 of it's primary use. , technically it's not error have showmessage
without ()
inside onclick
. showmesage
function definition, if type showmessage
, press enter in browser's console, return function definition , won't throw error. ides don't underline error because it's not error.
Comments
Post a Comment