Tuesday, August 19, 2008

MochiKit, IE6, and DOM manipulation

I'd recommend MochiKit to anyone who has to write Javascript code -- it lives up to its motto and "makes Javascript suck less." I'd recommend it twice as forcefully to Python coders, as features like the iteration tools are explicitly inspired by Python; and thrice as forcefully to any functional programming -minded Python coders, as it provides handy functions like map and zip, plus short-cuts for partial application and the like.

Bob Ippolito is a smart man.

MochiKit also provides some convenient DOM manipulation tools, such that swapping in a whole table takes only 3 or 4 lines of code:

swapDOM( $('mytable'),
TABLE({'id':'mytable'},
TBODY(null, [TR(null, TD(null, "a cell"))] ) );

(assuming you already had a DOM element w/ id='mytable')

A quick caveat, though: Internet Explorer 6 is picky about tables, and requires that a table created via the DOM have a TBODY or nothing will be displayed.

No comments: