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.
Code
·
Code improvement
·
Code rewrite
·
JavaScript
•
26. Feb 2006
Post a comment
Commenting on this post has expired.
|
Blog labels |