MochiKit.DOM: Easy API For DOM Manipulation
The MochiKit.DOM is an Application Programming Interface or API that helps in DOM manipulation without any difficulty. Basically, these DOM APIs are quite the nuances that you will encounter from very high dynamic languages but they offer reasonable basis for building something that runs smoothly. Taking significant inspirations from Nevow’s Stan, MochiKit.DOM lets you choose any tag and give it attributes before stuffing your desired objects into it. This highly dynamic API is aware of the fact that any string comes as a text node so that you need functions and expansion of array-like objects. In this way, the null values are skipped easily.
By using iterators offered by MochiKit.Iter, you can return the strings from their functions. What is more, you can develop this API with the registerDOMConverter. So, what are you waiting for? Use this API to create DOM elements. It depends on the demos like MochiKit.Base, MochiKit.Style and MochiKit.Iter, among which the last two are optional since the development of MochiKit 1.4.
The following rules are followed by CreateDOM for coercion in argument with DOM Nodes –
- Functions are regarded as “This” while first argument of parent node as well as the return value is displayed while ignoring “undefined” band “null”
- Iterables are subject to be flattened if the MochiKit.Iter is incorporated
- Strings will be wrapped up while objects having .dom(node) or ._dom_(node) methods are taken in consideration with parent node
- In case you cannot find an adapter, text node is created with .toString()
While creating the DOM Element Trees, you will be provided with easy tree tables that creates an easily comprehensible visual layout. If you wish to avoid passing any document or window variable to MochiKit.DOM, a context variable is used for each, which are managed by withDocument and withWindow features. currentWindow() and currentDocument() can be acquired thus.
DOM being easier to use and obtain flexible and correct result, is used in modifying innerHTML for making changes of documents.