Reputation: 273
I'm wondering if there is a significant difference between using CSS vs. DOM notation when manipulating objects in jQuery.
Say I want to change an object's background position, I could either use:
$(this).css({
'background-position' : xPos + 'px ' + yPos + 'px'
// ^
});
or:
$(this).css({
'backgroundPosition' : xPos + 'px ' + yPos + 'px'
// ^
});
I understand that the first is CSS notation and the second is DOM notation. The question here is: when does this matter? Are there any noticeable differences in terms of browser performance or other considerations that need to be taken into account?
Upvotes: 2
Views: 462
Reputation: 179086
jQuery automatically camel cases hyphenated CSS properties. It's probably slightly more efficient to just use the camel cased version, but you shouldn't even care because it's probably not a performance bottleneck.
You should use whichever version makes your code easier to read and understand.
Upvotes: 3