How to convert html object to string type?

I use jQuery method to get some type of html object:

var content = $('#cke_ckeditor iframe').contents().find('.cke_show_borders').clone();

Then I want to convert it to type string:

console.log(content[0].toString());

but the result:

[object HTMLBodyElement]

How can I turn it into a real string?

By the way, can I convert the converted html string to an html object?

+7
source share
6 answers

I believe you want to use Element.outerHTML :

console.log(content.outerHTML)

+22
source

You can try the following:

content.text();
+1
source

content[0].prop('outerHTML')

: jQuery ?

+1

.

var docString = "<html>"+content.documentElement.innerHTML+"</html>"

+1

jQuery :

var content = $ ('# cke_ckeditor'). find ('. cke_show_borders'). eq (0).clone();

console.log(content.get(0).outerHTML);

+1

Just use the String () function

String(obj)
0
source

All Articles