This module contains functions for constructing, modifying, and rendering
Dom.Element records.
By using a record to temporarily store data about a node, we can partially
construct that node with some data, but delay building it until all of the data
has been assembled. In this way, all of a node's data is available to be
modified until it is either placed in a container element or passed as an
argument to the Dom.Element.toNode function.
The rendering function wraps up the data collected in the element record as
arguments to VirtualDom.node. There is minimal overhead with this approach,
but where performance or memory use is of particular concern, it will be better
to construct nodes directly with the functions in module Dom.Node, or by using
the standard elm-lang/html and elm-lang/svg packages.
Construct an element that wraps text; the first argument gives the tag, and the second argument gives the internal text
"Hello World!"
|> Dom.Element.textWrapper "p"Construct an element that contains other elements; the first argument gives the tag, and the second argument gives a list of child elements
[ "Hello World!"
|> Dom.Element.textWrapper "p"
]
|> Dom.Element.container "div"Wrap a list of native VirtualDom nodes in a container element; the first
argument gives the tag, and the second argument gives a list of child nodes
[ "Hello World!"
|> Dom.Node.textWrapper "p" []
]
|> Dom.Element.wrapNodes "div"Generate a VirtualDom.Node from a Dom.Type.Element record
[ "Hello World!"
|> Dom.Element.textWrapper "p"
]
|> Dom.Element.container "div"
|> Dom.Element.toNodeUpdate an element's classes, replacing any existing classes; classes are
combined into a single className property when the rendering function is
called
myElement =
[ "Hello World!"
|> Dom.Element.textWrapper "p"
|> Dom.Element.withClasses
[ "size-large"
, "weight-bold"
]
]
|> Dom.Element.container "div"Add a new class to the existing classes of an element
myElement
|> Dom.Element.addClass "bordered-box"Remove a particular class from an element, retaining other assigned classes
myElement
|> Dom.Element.removeClass "bordered-box"Update an element's attributes, replacing any existing attributes
(You get the pattern by this point...)Add a new attribute to the existing attributes of an element
Update an element's text, replacing any existing text
Append new text to an element, after any existing text
Prepend new text to an element, before any existing text
Update an element's children, replacing any existing children
Append a new child to an element, after any existing children
Prepend a new child to an element, before any existing children
Update an element's children, with a list of native VirtualDom nodes given
as the first argument in place of a list of element records
Set an element's XML namespace
Returns True if the element has children
Returns True if the element has text
Returns True if the element's class list contains the name given in the
first argument
Construct a leaf element (an element without children), with the tag given as a string argument