onclick or onClick?
Solution 1:
Because some browsers (depending on the DOCTYPE) are tolerant of the inline onClick="something();"
attribute...it seems to have spread a bit, even into JavaScript questions where it doesn't work, since case matters.
Also, specifically to stackoverflow...people using it in questions...well, most of the time they wouldn't be asking a question if their code worked :)
Solution 2:
@Nick Craver pretty much has it nailed down and has my vote; I just wanted to add my thought.
I think it's onClick
is often used in conversation because it's a bit more readable, and as an old habit from those of us who predate all lowercase HTML. However, in code - both JavaScript and HTML, onclick
is correct and the only way it should appear. Even if you're using an older HTML doctype, stick to lowercase. If you ever update to a more strict doctype, you'll be glad your code doesn't need to be checked for case.
Solution 3:
It's just that for most browsers HTML attributes are case insensitive, but JS is case-sensitive. onClick will work in html, but if you're defining the handler in JS, you need to use the lowercased onclick.