|
TODO intro The code/**
* Cross browser function for setting the text content of an element.
* @param {Element} element The element to change the text content of
* @param {String} text The string that should replace the current element
* content with.
*/
goog.dom.setTextContent = function(element, text) {
if ('textContent' in element) {
element.textContent = text;
} else if (element.firstChild &&
element.firstChild.nodeType == goog.dom.NodeType.TEXT) {
// if the first child is a text node we just change its data and remove the
// rest of the children
while (element.lastChild != element.firstChild) {
element.removeChild(element.lastChild);
}
element.firstChild.data = text;
} else {
while (element.hasChildNodes()) {
element.removeChild(element.lastChild);
}
var doc = goog.dom.getOwnerDocument(element);
element.appendChild(doc.createTextNode(text));
}
};The code walkthroughTODO walkthrough Further readingTODO further reading
|