とある要素以下にある textNode で一致する textNode を XPath で高速に取り出す

  var getMatchedTextNode = function(text, target) {
            return document.evaluate(
               'descendant::text()[contains(., "' + text.replace(/"/g, '\\"') + '")]',
               target || document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
            ).singleNodeValue;
        }
http://subtech.g.hatena.ne.jp/secondlife/20091118/1258554379
原文地址:https://www.cnblogs.com/rubylouvre/p/1664885.html