2

For example, the CSS methods seem to be camelCase: http://api.jquery.com/category/css/,

But the mouse events are all lowercase: http://api.jquery.com/category/events/mouse-events/

Is there logic to this?

Elana
  • 43
  • 7
  • my guess is that the actual event keys are all lowercase. – Daniel A. White Sep 30 '15 at 18:06
  • 1
    If you imagine function names are like sentences then the first word is the verb and the second word (with the capital letter) is the direct object. "mousedown" is being seen as one word verb where "toggleClass" is 2 separate words. – Luminous Sep 30 '15 at 18:10

2 Answers2

3

In JavaScript, all events use lowercase identifiers (onclick, etc.). This is probably because it's an artifact of inline events in HTML.

CSS methods are in camelCase because that is the JavaScript convention. Event methods are in lowercase, probably because that's the HTML convention.

Take a look at this page for more details.

http://www.w3schools.com/tags/ref_eventattributes.asp

Richard Hamilton
  • 25,478
  • 10
  • 60
  • 87
2

The convention in JavaScript is to use camel case for identifiers. jQuery uses camel case for all method names, except for methods where the name is the same as event names.

In HTML the event names are not case sensetive, so variants like onmouseover, OnMouseOver and ONMOUSEOVER have been used. In XHTML the attribute names have to be lower case, and that is often used for HTML now as well, so that the code works for both HTML and XHTML.

In jQuery methods like mouseover and keypress are not camel case, they are lower case just like the onmouseover and onkeypress attributes as used in XHTML.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005