Tuesday, December 9, 2008

Using OO Javascript to create DOM elements and CSS Style

A lot of javascript tricks use CSS classes to toggle graphic properties, such as .mygoldbackground { ... } .mygreenbackground {...} and the js resets the classname of the HTML element. This is fine for most scenarios.

I am writing games where the CSS is much more dynamic, and I was constantly having to edit the CSS to match up with the game board layout ( for early prototype example of my players and game boards, see: http://my-toolbox.appspot.com/javascript.js?queryvalue=critters%201.2&dbtab=show )

So I am going to 1) create all game DOM elements with js 2) set all game DOM CSS with js.

Here is the core toolset of code for doing that: