Given a jQuery result set, how do you convert that back into plain HTML?
<div class="abc">
foo <strong>FOO</strong>
</div>
<div class="def">
bar
</div>
--
var $mySet = $('div');
Given $mySet
, how would you go about returning to the plain HTML above?
jQuery | html() Method The html() Method in jQuery is used to set or return the innerHTML content of the selected element. Syntax: It returns the content of first matched element. $(selector).html() It sets the content of matched element.
jQuery html() Method The html() method sets or returns the content (innerHTML) of the selected elements. When this method is used to return content, it returns the content of the FIRST matched element. When this method is used to set content, it overwrites the content of ALL matched elements.
Step 1: Firstly, we have to open that Html file in which we want to add the jQuery using CDN. Step 2: After then, we have to place the cursor between the head tag just before the title tag. And, then we have to use the <script> tag, which specify the src attribute for adding.
parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These methods do render all trailing or leading text (even if that's just whitespace).
i'd suggest creating a temporary container, then grabbing the html()
of that new container:
var html = $('<div>').append( $('div').clone() ).html();
alert(html);
// alerts:
<div class="abc">
foo <strong>FOO</strong>
</div><div class="def">
bar
</div>
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