New Prototype DOM Builder
Written by on May 17th, 2007 in Ajax News.
The Prototype team keeps going. Right after their latest 1.5.1 release the put a DOM Builder into the mix.
You can programatically great DOM nodes via:
-
-
new Element(’input’, { name: “user”, disabled: true });
-
This code will create:
-
-
<input name=”user” disabled=”disabled” />
-
The name will be correctly set in IE:
Experienced coders will remember that Internet Explorer doesn’t allow the name attribute to be set in a normal way. Well, we worked around that, too. This also demonstrates how boolean true as an attribute value results in repeating its name inside the value (disabled=”disabled”), which is a convention of XHTML.
The Element constructor demonstrated here sets attributes by using a method that’s also new: Element#writeAttributes. We should also mention that the constructor is optimized for speed when creating multiple instances of the same type. Using document.createElement() a lot to create nodes you will later manipulate with Prototype? You should use the Element constructor instead.
Source: Ajaxian
Original Article: http://ajaxian.com/archives/new-prototype-dom-builder