Переименуйте главное имя пользователя Amazon RDS

Другим, по общему признанию, менее элегантным решением, чем nickf или Shog9, было бы рекурсивно ходить DOM, начиная с & lt; body & gt; тег и добавьте каждый текстовый узел.

var bodyContent = document.getElementsByTagName('body')[0];
var result = appendTextNodes(bodyContent);

function appendTextNodes(element) {
    var text = '';

    // Loop through the childNodes of the passed in element
    for (var i = 0, len = element.childNodes.length; i < len; i++) {
        // Get a reference to the current child
        var node = element.childNodes[i];
        // Append the node's value if it's a text node
        if (node.nodeType == 3) {
            text += node.nodeValue;
        }
        // Recurse through the node's children, if there are any
        if (node.childNodes.length > 0) {
            appendTextNodes(node);
        }
    }
    // Return the final result
    return text;
}
21
задан Michael - sqlbot 3 June 2015 в 20:19
поделиться