JavaScript – Referencing CSS Properties Containing Hyphens or Dashes

by Michael Scepaniak on November 23, 2010 in software development

If, in JavaScript, you need to reference/manipulate CSS properties at runtime that contain a hyphen or dash in their names, omit the hyphen and, instead, camelcase the surrounding letters. You need to do this because hyphens in JavaScript variable names are illegal. For example, this won’t work: = "red"; = 3;

Whereas this will: = "red"; = 3;

Hope this helps.

Want to be notified when new articles are posted?
Enter your email address:

{ 0 comments… add one now }

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed

Previous post:

Next post:

Member of The Internet Defense League