DOMAssistantContent Module
The DOMAssistantContent module offers various methods for adding and removing content and elements to the page.
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, a number, or an HTML object.
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, a number, or a HTML object.
Return value
Element which called the method.
Example calls
$("container").replaceContent("<p>A new paragraph</p>");
$("container").replaceContent(document.createElement("p"));
replace(content, returnNew)
Replaces the current element with a new one.
Parameters
- content
- New content that can be specified either through an element, string or number reference.
- returnNew
- If set to true, the new element is returned; otherwise the replaced element is returned. Optional.
Return value
Either the replaced element or the new element.
Example calls
$("container").replace("<div><em>Way</em> cooler content!</div>");
var newElem = $$("placeholder").replace(elementRef, true);
remove()
Removes the current element.
Parameters
None.
Return value
Null.
Example calls
$("container").remove();