Magic DOM: Moving JavaScript forward
I have developed a 2 KB JavaScript library that does not depend on any external library. This library will improve your life in JavaScript for the better!
What does it do? Well, instead of doing this: var dl = document.createElement('dl');
dl.className = 'my_dl';
var dt_equ = document.createElement('dt');
dt_equ.innerHTML = 'Equipments';
dt_equ.className = 'my_dt';
dl.appendChild(dt_equ);
You can do this with MagicDOM: var dt_equ;
var dl = DL({'class': 'my_dl'},
dt_equ = DT({'class': 'my_dt'}, 'Equipments'));
You could also write this: SPAN({'class': 'babu'}, "Hello world")
->
<span class="babu">Hello world</span>
As you can see, the code gets more readable since it preserves the structure of HTML. The syntaxFollowing DOM elements are supported:
These are all functions that have following signature: DOMSHORTCUT({properties}?, ("String" | DOMSHORTCUT)*)
I.e. you can do following calls: LI({style: 'color: red'}, 'I am fluffy')
->
<li style="color: red">I am fluffy</li>
DIV(UL(LI('Hello', ' ', 'nasty')))
->
<div><ul><li>Hello nasty</li></ul></div>
Get started?Download MagicDOM.js: Source it: <script type="text/javascript" src="MagicDOM.js"></script>
You are ready to go :) Related postsCreditsMagicDOM is developed by me, but the initial idea is taken from MochiKit. MagicDOM can also be found in AJS [my own JavaScript library].
Announcements
·
Code
·
Code improvement
·
JavaScript
•
18. Jun 2007
8 comments so far
Post a comment
Commenting on this post has expired.
|
Blog labels |