I've encountered an issue while using the jQuery find
selector by Id with a div
and tbody
. Let me simplify my problem for better understanding.
HTML
<div id='iamdiv'>HELLO</div>
<table>
<tbody id='iamtbody'>
<tr><td>HELLO TOO</td></tr>
</tbody>
</table>
<input type='text' id='div'/>
<input type='text' id='tbody'/>
JS
$(document).ready(function() {
var allcontent = $($('body').html()); // I intentionally manipulated this
var $divcontent = allcontent.find('#iamdiv');
$('#div').val($divcontent.html());
var $tbodycontent = allcontent.find('#iamtbody');
$('#tbody').val($tbodycontent.html());
});
Fiddle: https://jsfiddle.net/bragboy/Lt8nua10/1/
In the input text boxes, only the raw html of the tbody
is displayed, not the div
. When attempting to use the filter
method instead of find
, it works for the div but not the tbody.
My goal is to find a consistent way to extract content from both divs and tbodys.