Sign in


Create new elements and content for inserting into the document.



Describes the elements or nodes to create. This may be a string, Object, Array or DOM node. The syntax is described below.

Return value

This method is chainable.

This method returns a Neon object containing all of the newly created elements, replacing the previous selection. In case the created elements included multiple levels of heirarchy, the returned object will contain the top level elements, and their children can be accessed by accessing their respective childNodes attributes.


This method allows you to create new DOM elements and other nodes for insertion into the document, using a convenient syntax. This method can create a single node, or multiple nodes at once in a heirarchical configuration.

specification syntax

The supplied specification will be used as a guide for creating the DOM nodes.

specification may be one of:

  • string

    A string represents a single DOM text node, whose contents shall be the the contents of the string.


    textnode ="Text content");
  • Object

    An object represents a single DOM element node.

    The object must have one property whose name is the name of the element, and whose contents represent the element's contents. This may be a string, Object or Array specification. This allows nodes to be nested inside other nodes. For an empty element, this may be null or the empty string ("").


    // Single list item
    listitem ={li: "List item"});

    // Unordered list with a list item nested inside
    mylist ={ul: {li: "List item"}});

    // Empty hr element
    ruler ={hr: null});

    An object may also contain one or more attributes. These are represented as properties whose name begins with an added dollar sign, and whose value is a string representing the attribute value.


    // Link
    mylink ={a: "Link text", $href: ""});

    // Image
    myimage ={img: null, $src: "image.gif", $alt: "Alt text"});

    The order of properties inside the object is not important, as long as there is one and only one property without a dollar sign, which will be used as the element name.

  • Array

    The specification may be an Array containing zero or more other strings, Objects and Arrays representing multiple sibling nodes.


    // Multiple list items at top level
    listitems =[{li: "Item 1"}, {li: "Item 2"}]);

    // Multiple cells in a table row
    tablerow ={tr: [{td: "Cell 1"}, {td: "Cell 2"}]});

The specification syntax is compatible with JSON, so it can be generated and transmitted by many server-side languages if necessary. It is expressive, taking up fewer bytes than the equivalent HTML would.

Instead of a specification conforming to the above JSON-compatible syntax, it is also possible to specify one or more already-created DOM nodes. This is more useful when using .append() or .insert(), as with those methods it provides a convenient way to move existing nodes around in the document.


The following simple example returns a single list item containing a text node:

listitem ={li: "List item text"});

The following complex example shows many nodes being created at once.

menuspec = {ul: [
{li: {a: "Yahoo", $href: ""}},
{li: {a: "Google", $href: ""}}
], $class: "menu"};
menu =;