Element

This represents almost everything in the DOM.

class Element {}

Constructors

this
this(Document _parentDocument, string _tagName, string[string] _attributes, bool _selfClosed)

Generally, you don't want to call this yourself - use Element.make or document.createElement instead.

this
this(string _tagName, string[string] _attributes)

Convenience constructor when you don't care about the parentDocument. Note this might break things on the document. Note also that without a parent document, elements are always in strict, case-sensitive mode.

Members

Functions

absoluteLeft
int absoluteLeft()
absoluteTop
int absoluteTop()

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

addEventListener
void addEventListener(string event, EventHandler handler, bool useCapture)
Undocumented in source. Be warned that the author may not have intended to support it.
addField
Element addField(string label, string name, string type, FormFieldOptions fieldOptions)

Tags: HTML, HTML5

addField
Element addField(Element label, string name, string type, FormFieldOptions fieldOptions)
Undocumented in source. Be warned that the author may not have intended to support it.
addField
Element addField(string label, string name, FormFieldOptions fieldOptions)
Undocumented in source. Be warned that the author may not have intended to support it.
addField
Element addField(string label, string name, string[string] options, FormFieldOptions fieldOptions)
Undocumented in source. Be warned that the author may not have intended to support it.
addSubmitButton
Element addSubmitButton(string label)
Undocumented in source. Be warned that the author may not have intended to support it.
appendChild
Element appendChild(Element e)

Appends the given element to this one. The given element must not have a parent already.

appendHtml
Element[] appendHtml(string html)

Appends the given html to the element, returning the elements appended

appendText
Element appendText(string text)

.

cloneNode
Element cloneNode(bool deepClone)

Clones the node. If deepClone is true, clone all inner tags too. If false, only do this tag (and its attributes), but it will have no contents.

dataset
DataSet dataset()

HTML5's dataset property. It is an alternate view into attributes with the data- prefix.

getAttribute
string getAttribute(string name)

Gets the given attribute value, or null if the attribute is not set.

getElementById
Element getElementById(string id)

.

getElementsByClassName
Element[] getElementsByClassName(string cn)

.

getElementsBySelector
Element[] getElementsBySelector(string selector)

Does a CSS selector

getElementsByTagName
Element[] getElementsByTagName(string tag)

.

getParent
T getParent(string tagName)

Gets the nearest node, going up the chain, with the given tagName May return null or throw.

hasAttribute
bool hasAttribute(string name)

Returns if the attribute exists.

insertAfter
Element insertAfter(Element where, Element what)

.

insertBefore
Element insertBefore(Element where, Element what)

Inserts the second element to this node, right before the first param

insertChildAfter
void insertChildAfter(Element child, Element where)

.

nodeValue
string nodeValue()

.

outerText
string outerText()

Same result as innerText; the tag with all inner tags stripped out

prependChild
Element prependChild(Element e)

Puts the current element first in our children list. The given element must not have a parent already.

querySelector
Element querySelector(string selector)

Note: you can give multiple selectors, separated by commas. It will return the first match it finds.

querySelectorAll
Element[] querySelectorAll(string selector)

a more standards-compliant alias for getElementsBySelector

removeAllChildren
void removeAllChildren()

Removes all inner content from the tag; all child text and elements are gone.

removeAttribute
Element removeAttribute(string name)

Removes the given attribute from the element.

removeChild
Element removeChild(Element c)

Removes the given child from this list.

removeChildren
Element[] removeChildren()

This removes all the children from this element, returning the old list.

replaceChild
Element replaceChild(Element find, Element replace)

.

replaceChild
void replaceChild(Element find, Element[] replace)

Replaces the given element with a whole group.

setAttribute
Element setAttribute(string name, string value)

Sets an attribute. Returns this for easy chaining

stealChildren
Element[] stealChildren(Element e, Element position)

.

swapNode
Element swapNode(Element child, Element replacement)

swaps one child for a new thing. Returns the old child which is now parentless.

toString
string toString()

Turns the whole element, including tag, attributes, and children, into a string which could be pasted into an XML file.

writeToAppender
string writeToAppender(Appender!string where)

This is the actual implementation used by toString. You can pass it a preallocated buffer to save some time. Returns the string it creates.

Mixins

__anonymous
mixin DomConvenienceFunctions!()
Undocumented in source.

Properties

childElements
Element[] childElements [@property getter]

.

childNodes
const(Element[]) childNodes [@property getter]

Returns the element's children.

childNodes
Element[] childNodes [@property getter]

Mutable version of the same

className
string className [@property getter]

Gets the class attribute's contents. Returns an empty string if it has no class.

className
string className [@property setter]

.

cloned
Element cloned [@property getter]

This is a full clone of the element

computedStyle
CssStyle computedStyle [@property getter]

.

firstChild
Element firstChild [@property getter]

Returns the first child of this element. If it has no children, returns null. Remember, text nodes are children too.

innerHTML
Appender!string innerHTML [@property setter]

Returns a string containing all child elements, formatted such that it could be pasted into an XML file.

innerHTML
Element innerHTML(string html, bool strict)
Html innerHTML [@property setter]

Takes some html and replaces the element's children with the tree made from the string.

innerRawSource
string innerRawSource [@property setter]

This sets the inner content of the element *without* trying to parse it. You can inject any code in there; this serves as an escape hatch from the dom.

innerText
string innerText [@property getter]

Fetch the inside text, with all tags stripped out.

innerText
string innerText [@property setter]

Sets the inside text, replacing all children. You don't have to worry about entity encoding.

lastChild
Element lastChild [@property getter]
nextSibling
string nextSibling [@property setter]

.

nodeType
int nodeType [@property getter]

.

opDispatch
string opDispatch [@property setter]

Provides easy access to attributes, object style.

outerHTML
string outerHTML [@property setter]

Replaces this node with the given html string, which is parsed

outerHTML
string outerHTML [@property getter]

Returns all the html for this element, including the tag itself. This is equivalent to calling toString().

outerText
string outerText [@property setter]

Strips this node out of the document, replacing it with the given text

previousSibling
string previousSibling [@property setter]

.

style
ElementStyle style [@property getter]

Provides both string and object style (like in Javascript) access to the style attribute.

style
string style [@property setter]

This sets the style attribute with a string.

tree
ElementStream tree [@property getter]

Returns a lazy range of all its children, recursively.

Static functions

make
Element make(string tagName, string childInfo, string childInfo2)

Convenience function to try to do the right thing for HTML. This is the main way I create elements.

make
Element make(string tagName, Html innerHtml, string childInfo2)
Undocumented in source. Be warned that the author may not have intended to support it.
make
Element make(string tagName, Element child, string childInfo2)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

attributes
string[string] attributes;

This is where the attributes are actually stored. You should use getAttribute, setAttribute, and hasAttribute instead.

bubblingEventHandlers
EventHandler[][string] bubblingEventHandlers;
Undocumented in source.
capturingEventHandlers
EventHandler[][string] capturingEventHandlers;
Undocumented in source.
children
Element[] children;
Undocumented in source.
defaultEventHandlers
EventHandler[string] defaultEventHandlers;
Undocumented in source.
expansionHook
void* expansionHook;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

hasLayout
bool hasLayout;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

offsetHeight
int offsetHeight;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

offsetLeft
int offsetLeft;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

offsetParent
Element offsetParent;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

offsetTop
int offsetTop;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

offsetWidth
int offsetWidth;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

parentDocument
Document parentDocument;

Get the parent Document object that contains this element. It may be null, so remember to check for that.

parentNode
Element parentNode;

.

tagName
string tagName;

The name of the tag. Remember, changing this doesn't change the dynamic type of the object.

zIndex
int zIndex;

These properties are useless in most cases, but if you write a layout engine on top of this lib, they may be good +////ditt

Meta