Attack of the camelCasing

20060318144

There are two ways to set attributes of a page element using JavaScript. The preferred is the setAttribute method of the DOM specification. The older, less portable, is using the value method on a particular element. p.setAttribute("class","feature"); and p.class = "feature"; both do the same thing and are compatible with most modern browsers.

The XHTML specification indicates that all attributes should be lowercase in properly formed markup. However, when using JavaScript to generate or change attribute values, following this specification sometimes results in code that does not work across all broswers, Internet Explorer being the bugger. To IE, the seemingly correct lowercase colspan is ignored in favor of the camel cased version colSpan. This is true for both the setAttribute and value methods. That said, to make a five column data cell, use thetd.setAttribute("colSpan",5);.

Comments

  1. majafa 20060318

    sure yeah. does this have anything to do with old computers, DOS and NFS? No? oh well.

  2. matches 20060319

    I never knew that camelCasing was the proper term for that kind of thing. So while the general point of this post is lost on me, at least I learned something.


Skateboards and bikes are better at nights

Skateboards and bikes are better at nights. 0 comments.


Search WayTooCrowded
The Header Should Always Point Home