Monday, August 04, 2008

JavaScript, CSS and hyphens*

Monday, August 04, 2008 6:43:28 PM (GMT Standard Time, UTC+00:00)

These are just a few quick tips that I stumbled across a few seconds ago to bear in mind when working with CSS in JavaScript.

Tip 1:
Compounded CSS attributes lose the hyphen and the second (third, forth, etc) word have an Upper Case first letter. For example: background-color (in CSS style) becomes backgroundColor (in JavaScript) and text-align (in CSS style) becomes textAlign (in JavaScript).

Tip 2:
Compounded HTML attributes use Upper Case first letter for second (third, forth, etc) word. For example: colSpan, bgColor, readOnly

Tip 3:
HTML "class" becomes JavaScript "className".

These tips were sourced from this web developer forum.

(I must say that I've only validated Tip 1. Feel free to comment on any of the others.)

Related posts:
13 Predictions for 2009
Why “Open Source” misses the point of Free Software
Top 25 days in computing history
How 10 Famous Technology Products Got Their Names
Google pushing Chrome via Youtube
Google's Android mobile unveiled

Comments are closed.