Is it possible to use jQuery to read/parse a selection of valid HTML such that you can use jQuery methods on it such as .val() or .html()?
The below is not working for me. I have tried .html() and .val().
html = $.parseHTML('<div id="one">blah</div><div id="two">blurp</div>');
console.log ($(html).find('#one').text());
No need to use parseHTML on HTML string.
Wrap it in jQuery object and use methods on it.
var html = $('<div id="one">blah</div><div id="two">blurp</div>').filter('#one').html();
document.write(html);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With