<!DOCTYPE html>
<title></title>
<body>
<div id="hoge">
<h3>岩手県の<em>最北</em>の町</h3>
<p><em>洋野町</em>に住んでいる〜!</p>
<p>I live in the <em>northernmost town</em> in Iwate.</p>
</div>
<script>
var findText = function findText (root, searchString, iSearchScope, iFlags) {
var text = [ ];
if (! root || ! searchString) return null;
(function ( n ) {
var m;
while (true) {
if (3 == n.nodeType)
text.push (n.nodeValue.replace (/^\s+|\s+$/g, '\u0020'));
if (n.hasChildNodes ())
n = n.firstChild;
else
while (true) {
m = n;
if (n = n.nextSibling)
break;
n = m.parentNode;
if (n === root)
return;
}
}
})(root);
text = text.join ('');
if ('number' === typeof iSearchScope)
text = iSearchScope < 0
? text.substring (0, text.length + iSearchScope)
: text.substring (iSearchScope, text.length);
if ((iFlags || 0) & 4) {
text = text.toLowerCase ();
searchString = searchString.toLowerCase ();
}
if ((iFlags || 0) & 2)
return text === searchString;
return -1 !== text.indexOf (searchString);
};
var node = document.getElementById('hoge');
alert (findText (node, '最北の町'));
</script>