Creating DOM elements the COOL way

MochiKit has a really nice way to create DOM elements. I have created my own improved version of this, that does not rely on MochiKit (or anything else for that matter).
P()
->
<p></p>

Instead of doing:

document.createElement("p")

Here are some examples:

SPAN({'class': 'babu'}, "Hello world")
->
<span class="babu">Hello world</span>
SPAN({'class': 'babu'}, P(), IMG({'src': 'image.gif'}))
->
<span class="babu"><p></p><img src="image.gif" /></span>

I hope you get the idea. This works for most of the DOM elements.

See the code JavaScript code [63 lines]

Code · Code improvement · Code rewrite · JavaScript 26. Feb 2006
1 comment so far

shit don't work. yo.

Post a comment
Commenting on this post has expired.
© 2000-2009 amix. Powered by Skeletonz.