JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<h1 id="top">Selector Test Kit</h1>
<textarea id="domain" name="domain"><body><p>Paragraph Here</p></body></textarea>
<input type="text" id="selector" name="selector" value="p" />
<p>Target: <span id="target"></span></p>
</div>
CSS
#top { margin-bottom: 10px; font-size: 150%; font-weight: bold; }
#target { color: #f00; cursor: pointer; }
#domain { width: 400px; }
#selector { width: 400px; clear: both; margin-bottom: 10px; }
JavaScript
$('#domain,#selector').change(function() {
var textContent = $($('#selector').val(), '<div>' + $('#domain').val() + '</div>').text();
if (textContent == '') {
textContent = '« not found »';
}
$('#target').text(textContent);
}).keyup(function() {
$(this).change();
}).change();