Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is camel case used in 'getElementById' but not in 'onclick'? [closed]

Tags:

javascript

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!";
like image 720
Jerald George Avatar asked May 24 '18 14:05

Jerald George


1 Answers

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.

like image 113
Scott Marcus Avatar answered Nov 06 '22 17:11

Scott Marcus