Wednesday, March 29th, 2006
At one point early on, I decided to write a wrapper function for document.createElement to avoid typing that out so often, and ended up realizing I should reduce more typing by figuring out a way to pass in attributes like the class and ID to be set. And then I realized, and it feels obvious in retrospect, that it should be able to handle creating a whole tree. I’m sure I’m not the first person to think of this, or even to write such a function. But I have found this to be very useful, and so after getting permission to do so from my company, I came here to release it as open source.
The document.createElement code creates a “$E()” function as an add-on to the power that Prototype already presents. Given the data of the object to create (tag, className, id), dropping a new element into the page is quick and painless. Best of all, it supports adding children at the same time, cutting dramatically down on the multiple calls.
The post includes a description of the add-on, the code to drop into you installation and a sample showing how to add a DIV tag with other child DIVs (one including an anchor tag).
Posted by Chris Cornutt at 7:38 pm