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 parentElemElement - Source:
-
(static) fetchAttributeValuesToArray(elem, namespaceURI) → {Array}
-
Fetch all attribute values into an array
Parameters:
Name Type Description elemObject namespaceURIString 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 elemObject namespaceURIString 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 nodeDOMNode nodeTypesArray - Source:
-
(static) getDataAttrib(elem, attribName) → {String}
-
Get value of HTML5 data-* attribute.
Parameters:
Name Type Description elemObject attribNameString - Source:
Returns:
- Type
- String
-
(static) getDataset(elem) → {Hash}
-
Fetch whole HTML dataset of elem.
Parameters:
Name Type Description elemObject - Source:
Returns:
- Type
- Hash
-
(static) getDirectChildElems(elem, tagName, localName, namespaceURI) → {Array}
-
Get first level element children of elem.
Parameters:
Name Type Description elemObject tagNameString localNameString namespaceURIString - 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 elemObject attribValuesArray Array of hash ({attrib: value}). tagNameObject localNameObject namespaceURIObject - 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 elemObject tagNameString localNameString namespaceURIString - 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 elemOrAttribObject - Source:
Returns:
- Type
- String
-
(static) getNearestAncestorByTagName(elem, tagName, includingSelf) → {Object}
-
Get nearest ancestor element with specified tag name.
Parameters:
Name Type Description elemObject tagNameString includingSelfBool 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 elemElement attribNameString - Source:
Returns:
- Type
- Bool
-
(static) isDescendantOf(childElem, parentElem) → {Bool}
-
Check if childElem is inside parentElem.
Parameters:
Name Type Description childElemObject parentElemObject - Source:
Returns:
- Type
- Bool
-
(static) isElement(obj)
-
Check if an object is element.
Parameters:
Name Type Description objVariant - Source:
-
(static) isInDomTree(node, doc) → {Bool}
-
Check if node has been inserted to DOM tree of document.
Parameters:
Name Type Description nodeDOMNode docDocument - 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 nodeObject namespaceURIString allowEmptyNamespaceBool 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 elemHTMLElement newTagNameString - Source:
Returns:
New element created.- Type
- HTMLElement
-
(static) setDataAttrib(elem, attribName, value)
-
Set value of HTML5 data-* attribute.
Parameters:
Name Type Description elemObject attribNameString valueString - 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: