Check out what Dan Webb has done: he has put together a very lightweight script to take the tedium out of creating markup with the DOM. As he explains:
Typing out big lists of
createElement
s,setAttribute
s andappendChild
s is not my idea of fun. Even creating the most trivial stuff with these methods is extremely tedious.
Using Dan’s script, you can generate markup using the DOM but in a very HTML-like manner.
His solution is very elegant and doesn’t dictate what happens to the generated markup: it’s still up to you to determine how the generated markup is inserted into your document.
Dan also notes that similar functionality is built into libraries like Mochikit but I like having the option to just cherry-pick this one handy, lightweight script.
Posted by Jeremy on Thursday, April 6th, 2006 at 11:13pm
Comments
I like his way of defining things such that you get an error if you call an HTML element that doesn’t exist (e.g. html.TITTLE). Very cute. This shows of metaprogramming at its best.
# Posted by Dominic Mitchell on Friday, April 7th, 2006 at 5:11pm
Sorry. Comments are closed.