Sign in

.append()

Create new elements and append them to the contents of the selected elements, or move elements from another location into the selected elements.

Syntax

neon.append(specification)

specification

Describes the elements or nodes to place into the document. This may be a string, Object, Array, or DOM node, whose syntax is described under .build().

Return value

This method is chainable.

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

Description

This method allows you to create new DOM elements and other nodes, and append them to the selected elements.

This method also allows you to move nodes from one part of the document to another. If the element (or elements) supplied in the specification argument is already part of the document, it will be moved to its new location.

When moving from a single destination to multiple destinations, the element will be moved to the first destination, then cloned multiple times so that copies are inserted at the other destinations too.

specification syntax

Please see .build() for the syntax required to build new nodes.

Examples

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

neon.select("#header ul").append({li: "List item text"});

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

menuspec = {ul: [
{li: {a: "Yahoo", $href: "http://yahoo.com"}},
{li: {a: "Google", $href: "http://google.com"}}
], $class: "menu"};
neon.select("#footer").append(menuspec);

The following example demonstrates how .append() can be used to move a node from one location to another:

neon.select("#complete").append(neon.select("#inprogress li"));