DOMAssistantContent Module

The DOMAssistantContent module offers various methods for adding and removing content and elements to the page.

prev()

Gets a reference to the previous HTML element, automatically bypassing any text nodes that might in between.

Parameters

None.

Return value

Element's previous sibling element.

Example calls

$("container").prev();

next()

Gets a reference to the next HTML element, automatically bypassing any text nodes that might in between.

Parameters

None.

Return value

Element's next sibling element.

Example calls

$("container").next();

create(name, attr, append, content)

Creates an element, and optionally sets attributes on it, appends it to the current element and adds content to it.

Parameters

name
Tag name for the new element. Required.
attr
An object containing attributes and their values. Optional.
append
Boolean if the new element should be appended right away. Optional.
content
A string or HTML object that will become the content of the newly created element. Optional.

Return value

Element created by the method.

Example calls

$("container").create("div");

$("container").create("div", {
id : "my-div",
className : "my-class"
});

$("container").create("div", null, false, "Hello!");

$("container").create("div", {
id : "my-div",
className : "my-class"
}, true, "Hi there!");

setAttributes(attr)

Sets attributes on the current element.

Parameters

attr
An object containing attributes and their values. Required.

Return value

Element which called the method.

Example calls

$("container").setAttributes({
id : "my-div",
className : "my-class"
});

addContent(content)

Adds content to the current element.

Parameters

content
Can either be a string, which will then be applied using innerHTML, or an HTML object that will be applied using appendChild.

Return value

Element which called the method.

Example calls

$("container").addContent("<p>A new paragraph</p>");

$("container").addContent(document.createElement("p"));

replaceContent(newContent)

Replaces the content of the current element with new content.

Parameters

newContent
Can either be a string, which will then be applied using innerHTML, or a HTML object that will be applied using appendChild.

Return value

Element which called the method.

Example calls

$("container").replaceContent("<p>A new paragraph</p>");

$("container").replaceContent(document.createElement("p"));

remove()

Removes the current element.

Parameters

None.

Return value

Null.

Example calls

$("container").remove();

Get your copy