Why is this JavaScript code with $ sign not working? -
html file
<div id="myid"></div>
are these codes possible or not valid in javascript?
1.
function $(id) { return document.getelementbyid(id); }
2.
$("myid").innerhtml = "hello world";
below codes possible or not in javascript ?
the answer yes, code fine.
there nothing wrong code you've shown. many commenters have pointed out, works fine in js fiddle.
$
not, 1 commenter said, reserved word, see https://developer.mozilla.org/en-us/docs/web/javascript/reference/reserved_words
however, recommend against using $
if code used others. $
used shortcut jquery, confusing commenters. believe (for readability) better off using different single character.
Comments
Post a Comment