tags:

views:

24

answers:

1

In jQuery, are multiword css fields condensed to camelCaps? For instance.

$("#item").css("marginBottom"); 

not

$("#item").css("margin-bottom"); 

On my machine running Firefox 3.6.6 with jQuery JavaScript Library v1.4.2, the answer seems to be no. doing $("#item").css("marginBottom"); gives me a warning about invalid css field and that the declaration was dropped.

+2  A: 

Actually I'm wrong - it seems internally it camelCases it. Here's a snippet of code that grabs the margin bottom ( tested in Fx 3.6 ):

el = document.body;
$('el').css('margin-bottom', '20px')
computed = document.defaultView.getComputedStyle( el, null )

computed['marginBottom'] // 0px

Update: Here's the camelcasing then lowercasing code from jQuery:

x = 'marginBottom'.replace( /([A-Z])/g, '-$1').toLowerCase()
meder
So the camelCasing is only for plain javascript then right?such as x.style.marginBottom="15px"
Razor Storm
yes, the properties are camelCase.
meder
That makes sense then, the properties themselves had to be camelCased to comply with javascript's variable naming conventions, but since jQuery represents them as strings, having the little dash is ok.
Razor Storm