|
|
Dollar E: A document.createElement Wrapper on Prototype
|
03/30/2006, By Ajax Impact News
|
Over the Arantius.com Anthony Lieuallen has posted an wrapper for document.createElement to create an UI element on your page that made use of Ajax. He have used Prototype JavaScript library as base to write this wrapper.
He writes "The primary new feature ( from my perspective ;-) ) was a brand new UI that made use of AJAX, which I built on top of the Prototype JavaScript library. There was a lot of dynamic element creation based on the data coming back from the AJAX calls, and thus a lot of document.createElement calls, along with the appendChild and insertBefore and the element-property-setting statements. It's very verbose.
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."
Anthony have named this wrapper as function $E() or "Dollar E". As he saw that it is the reverse of the $() function in prototype. The $() function gets an element that exists, the $E() function creates a new element that doesn't. It is passed a custom data structure, and it returns a (tree of) DOM element(s).
You can check out the sample source code and an example, and the HTML string produced by running the example also.
Sponsered Link:
Explore It...
|
Rate this Ajax News
Rating: 0.0 out of votes cast
| |
|
|
| |
|
|
|
|
|
|
|
|