While learning JavaScript, I noticed that some of the functions, for instance getElementById()
, are in camel case while the onclick
is not.
I would like to know why there is a difference in the function naming in JavaScript.
document.getElementById("demo").onclick = function() {myFunction()};
document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
onclick
is a property that has its roots as an HTML attribute, first established in the very early days of the Web - - back before we had standards. As JavaScript (and ECMAScript) evolved, standards emerged.
This is why the web of today has many "exceptions" to what we now consider to be standards. We just can't go back and change what has become "de facto" standards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With