Class HTMLDocument


class HTMLDocument
Extends the native HTMLDocument and document with functionality for easy cross-browser HTML node creation.
Authors:
Henrik Lindqvist <henrik.lindqvist@llamalab.com>
Version:
Defined in HTML.js

Function Summary
Node createHTML(string name, [Object attrs], [Array children])
Node createHTML(string text)
Create HTML node’s.

Function Details

function createHTML

Node createHTML(string name, [Object attrs], [Array children])
Node createHTML(string text)
Node createHTML(Node node)
Create HTML node’s.

A fast and simple way to create HTML DOM nodes at runtime.

Example:

   // Since input are self-contained in a single JavaScript object, 
   // templates can be remotely loaded as JSON. 
   var json = ['A',{href:'http://llamalab.com'},['LlamaLab']];
   var llamalab = document.toHTML.apply(document, json);
   // Creating a DOM tree.
   document.body.appendChild(document.createHTML(
     'UL',[
       'LI',llamalab,
       'LI',['A',{href:'http://slashdot.org'},['Slashdot']],
       'LI',[document.getElementById('moveThisLink')],
     ]
   ));
 
Parameters:
Element Syntax
name - Element tag name.
[attrs] - Object with attributes.
[children] - Array with children, with same syntax as this function.
Text (node) Syntax
text - Text node content.
Node Inclusion Syntax
node - Node to include as child.
Returns:
Element, Text (node) or DocumentFragment