new DomUtils()
An class with static methods handle HTML or XML DOM.
- Source:
Methods
-
(static) clearChildContent(parentElem)
-
Clear child element/text node but reserves attribute nodes.
Parameters:
Name Type Description parentElem
Element - Source:
-
(static) fetchAttributeValuesToArray(elem, namespaceURI) → {Array}
-
Fetch all attribute values into an array
Parameters:
Name Type Description elem
Object namespaceURI
String useLocalName.
Boolean Whether fetch attribute's localName rather than name. - Source:
Returns:
Each item is a hash: {name: '', value: ''}.- Type
- Array
-
(static) fetchAttributeValuesToJson(elem, namespaceURI) → {Hash}
-
Fetch all attribute values into an JSON object
Parameters:
Name Type Description elem
Object namespaceURI
String useLocalName.
Boolean Whether fetch attribute's localName rather than name. - Source:
Returns:
Each item is a hash: {name: value}.- Type
- Hash
-
(static) getChildNodesOfTypes(node, nodeTypes)
-
Returns a list of child nodes with specified type.
Parameters:
Name Type Description node
DOMNode nodeTypes
Array - Source:
-
(static) getDataAttrib(elem, attribName) → {String}
-
Get value of HTML5 data-* attribute.
Parameters:
Name Type Description elem
Object attribName
String - Source:
Returns:
- Type
- String
-
(static) getDataset(elem) → {Hash}
-
Fetch whole HTML dataset of elem.
Parameters:
Name Type Description elem
Object - Source:
Returns:
- Type
- Hash
-
(static) getDirectChildElems(elem, tagName, localName, namespaceURI) → {Array}
-
Get first level element children of elem.
Parameters:
Name Type Description elem
Object tagName
String localName
String namespaceURI
String - Source:
Returns:
Direct element children of elem.- Type
- Array
-
(static) getDirectChildElemsOfAttribValues(elem, attribValues, tagName, localName, namespaceURI)
-
Get first level element children of elem with given attrib values
Parameters:
Name Type Description elem
Object attribValues
Array Array of hash ({attrib: value}). tagName
Object localName
Object namespaceURI
Object - Source:
-
(static) getElementText()
-
Get text content of an element. This function will not consider child elements, just direct text.
- Source:
-
(static) getFirstChildElem(elem, tagName, localName, namespaceURI) → {Array}
-
Get first element child of elem.
Parameters:
Name Type Description elem
Object tagName
String localName
String namespaceURI
String - Source:
Returns:
Direct element children of elem.- Type
- Array
-
(static) getLocalName(elemOrAttrib) → {String}
-
Get local name of element. In standard browser, this function should return elem.localName. However, IE (<= 8) does not implement localName property, so we have to check baseName or nodeName instead.
Parameters:
Name Type Description elemOrAttrib
Object - Source:
Returns:
- Type
- String
-
(static) getNearestAncestorByTagName(elem, tagName, includingSelf) → {Object}
-
Get nearest ancestor element with specified tag name.
Parameters:
Name Type Description elem
Object tagName
String includingSelf
Bool If true, elem will also be check if it is in tagName - Source:
Returns:
- Type
- Object
-
(static) hasAttribute(elem, attribName) → {Bool}
-
Check if elem has an attribute.
Parameters:
Name Type Description elem
Element attribName
String - Source:
Returns:
- Type
- Bool
-
(static) isDescendantOf(childElem, parentElem) → {Bool}
-
Check if childElem is inside parentElem.
Parameters:
Name Type Description childElem
Object parentElem
Object - Source:
Returns:
- Type
- Bool
-
(static) isElement(obj)
-
Check if an object is element.
Parameters:
Name Type Description obj
Variant - Source:
-
(static) isInDomTree(node, doc) → {Bool}
-
Check if node has been inserted to DOM tree of document.
Parameters:
Name Type Description node
DOMNode doc
Document - Source:
Returns:
- Type
- Bool
-
(static) namespaceMatched(node, namespaceURI, allowEmptyNamespace) → {Bool}
-
Check if node.namespaceURI == namespaceURI or no namespace info on node
Parameters:
Name Type Description node
Object namespaceURI
String allowEmptyNamespace
Bool Whether return true if node.namespaceURI is empty - Source:
Returns:
- Type
- Bool
-
(static) replaceTagName(elem, newTagName) → {HTMLElement}
-
Replace tag name of element. This method actually create a new element and replace the old one.
Parameters:
Name Type Description elem
HTMLElement newTagName
String - Source:
Returns:
New element created.- Type
- HTMLElement
-
(static) setDataAttrib(elem, attribName, value)
-
Set value of HTML5 data-* attribute.
Parameters:
Name Type Description elem
Object attribName
String value
String - Source:
-
(static) setElementText()
-
Set text content of an element. This function will not consider child elements, just replace current first text node or append a new text node to the tail of element's children.
- Source: