Creating DOM elements the COOL way
Posted on 26. Feb 2006
· Comments [1]
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. Post a comment
Commenting on this post has expired.
|
Blog labels |