JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
</head>
<body>
<p>search me</p><b> I could be the answer</b>
<p>search me</p><b> I could be the answer</b>
<div>
<button class="btn-display" data-display="inline">Inline</button>
<button class="btn-display" data-display="block">Block</button>
<button class="btn-display" data-display="inline-block">Inline-Block</button>
</div>
<div>
<textarea id="res"></textarea>
</div>
</body>
</html>
CSS
#res {
width: 400px;
height: 300px;
resize: none;
}
div {
margin: 7px 0;
}
JavaScript
function _find(str) {
var div = document.createElement('div');
div.innerHTML = document.body.innerHTML;
var elements = div.getElementsByTagName('*');
for(var i = elements.length; 0 > i--;) {
elements[i].style.display = 'inline';
}
return (div.innerText || div.textContent).indexOf(str) > -1;
}
function containsStr(str) {
return (document.body.innerText || document.body.textContent).indexOf(str) > -1;
}
function containsStrEx(str) {
return (document.body.innerText || document.body.textContent)
.replace("\n", "")
.indexOf(str) > -1;
}
function containsStr$(str) {
return $('body:contains("'+str+'")').length > 0;
}
function test(str) {
printLn('_find(str): ', _find(str));
printLn('containsStr(str): ', containsStr(str));
printLn('containsStrEx(str): ', containsStrEx(str));
printLn('window.find(str): ', window.find(str));
printLn('jQuery :contains selector: ', containsStr$(str));
printLn(SEPARATOR);
}
var str = "me I could be",
console$ = $('#res'),
SEPARATOR = new Array(32).join('-');
function printLn(s) {
print(Array.prototype.join.call(arguments, ''), "\n");
}
function print(s) {
console$[0].value += Array.prototype.join.call(arguments, '');
console$.scrollTop(console$[0].scrollHeight - console$.height());
}
$(document).on('click', '.btn-display', function() {
$('p').css('display', $(this).data('display'));
test(str);
});