Static
s_Maps certain characters to their entity or special html tag or empty string if it has no use in html
Static
addCombines UFHtml.addClasses and UFHtml.removeClasses.
Element to add and remove the classes to and from; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case no classes are added.
Css classes separated by a space character; can be null, in that case no classes are removed.
Static
addAdds a listener to the body element for one or more events. If the target or any of the parents of the target matches the selector, the listener is called. The function returns a callback, which can be called to remove the listener. This method can be used to handle events fired by elements that are dynamically added at a later time.
Selector the target must match.
One or more events to add listener for (separated by space)
A factory function that creates a handler callback for the element. Note that this function is called everytime an event is fired. The function should take as little time as possible.
a function that can be called to remove the listener from the body.
Static
addAdds css classes in a single string to an element.
Element to add the classes to; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case nothing happens.
Static
addAdds a listener for one or more events. The function returns a callback, which can be called to remove the listener.
Element to add listener to or selector for the element
One or more events to add listener for (separated by space)
Listener callback
a function that can be called to remove the listener from the element for the events.
Static
addAdds a listener for one or more events to an element or a list of elements. The function returns a callback, which can be called to remove all the listener.
a function that can be called to remove all the added listener from the elements for the events.
Static
assignAssigns a value to a form field element and triggers the "input"
and "change"
events.
With checkbox/radio elements the following values will set the checked state to true: 'true', '1', 'checked'. Any other value will set the checked state to false.
If the element is not a form field element, nothing happens.
Element to assign to
Value to assign
true
if the value could be assigned, false
if the element is not a form field.
Static
buildBuilds a map of data attributes from the element. The method will skip data attributes that start with 'data-uf-'.
The result can be used with UFHtml.copyAttributes.
Element to get data attributes from.
an object where the keys are the attribute names and the values are the attribute enclosed by square brackets.
Static
convertConverts a html formatted text to a plain text.
Based on code from: https://javascript.plainenglish.io/3-ways-to-convert-html-text-to-plain-text-strip-off-the-tags-from-the-string-4c947feb8a8c
Html text to format
plain version of the text
Static
copyCopies one or more attribute values to elements. Depending on the type of the element the value gets handled as follows:
input
: the checked
or value
property is set (depending on the type
).textarea
: the value
property is set.select
: the value
property is set.img
: the src
property is set.Element to get the attributes from
The field names are used as attribute names and the values are used as selectors for the target elements. If the selector points to multiple elements, each element will get the attribute value.
Optional
container: DocumentFragment | ElementContainer to search the target elements in; if not set, the document
is used.
Static
createCreates an element by parsing a piece of html.
Html to parse
created element; the element is removed from the document before it is returned.
Static
emptyRemoves all child elements from an element.
Element to remove all children of.
Static
escapeConverts plain text to html by replacing certain characters with their entity equivalent and
replacing \n with
tags.
Based on code from answer: https://stackoverflow.com/a/4835406/968451
Text to convert
Html formatted plain text
Static
fadeFades in an element by setting the styles opacity and transition.
Element to fade in
Duration in millisecond for the fade in transition (default = 400)
Static
fadeFades out an element by setting the styles opacity and transition.
Element to fade out
Duration in millisecond for the fade in transition (default = 400)
Static
findGets all elements for an attribute.
Attribute name
Attribute value or use null
to ignore value
Optional
container: ElementContainer to search the element in; if not set, the document is used.
found elements
Static
findTries to find an element for an attribute.
Attribute name
Attribute value or use null
to ignore value
Optional
container: ElementContainer to search the element in; if not set, the document is used.
found element or null
if no element could be found
Static
getGets an element for a selector. If the selector is an element, it just returns the element.
If the selector is a string, it will try to find the element in the document or container.
If no element can be found or the selector is a null value, the method will throw an error.
Element, selector text or null
Optional
container: ElementContainer to search the element in; if not set, the document is used.
found element
Static
getGets the value of an attribute.
Element to get attribute from
Name of attribute
Default value to return if no value could be determined (default = '')
the value of the attribute or aDefault
if there is no value.
Static
getGets all attribute names of an element.
Element to get the attribute names from
all the names of attributes defined at the element
Static
getGets the first parent element of the element that matches the selector.
Element to get the parent (or grandparent or great-grandparent) of
Selector to filter the parent with
the parent element that matches the selector or null if no parent could be found
Static
getGets an element for an attribute.
If no element can be found the method will throw an error.
Attribute name
Attribute value or use null
to ignore value
Optional
container: ElementContainer to search the element in; if not set, the document is used.
found element
Static
getGets an element for a dom ID and typecast it to a certain type.
If no element can be found, the method will throw an error.
The dom id of element
found element
Static
getGets all parents of an element.
Element to get all parents for
Optional
selector: stringOptional selector to filter the parents with
all parent elements of the element (parent, grandparent, great-grandparent, etc.)
Static
hasChecks if an element has an attribute.
Element to check attribute for
Name of attribute
true
if the element has the attribute, false
if not.
Static
hideHides an element by updating the display
style property. The current value is stored in the
element and is used by show. Then the value 'none' is assigned to display
style.
Element to hide
Static
insertInserts an element after another element.
Parent to insert the element in
Element to insert
Element to insert the new element after
Static
isChecks if an element is visible, that it is not hidden by some styling and the element has some size.
Element to check
True to check the parents of the element as well, false to only check the element itself.
true
if the element is visible, false
if not. Note that if only element itself
is checked, it does not take into account of any parent is not visible.
Static
reloadReloads the current page. It removes the current page from the history and then reloads the page. Any post data is no longer used and the page with the post data is no longer in the history.
Static
removeRemoves css classes in a single string from an element.
Element to remove the classes from; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case nothing happens.
Static
showShows a element by updating the display
style property.
Element to show
Optional
display: stringWhen set use this value, else use the initial value which was copied with hide. If there is no initial value, use 'block'.
Static
toggleToggle css classes in a single string in an element.
Element to add to or remove from the classes; can be null, in that case nothing happens.
Css classes separated by a space character; can be null, in that case nothing happens.
Optional
force: booleanIf true the classes are added, if false the classes are removed, if not set the classes are toggled.
UFHtml implements methods for supporting html and the dom.