Search code examples
stringhtml-parsing

How to convert the 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 string type:

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

but the result is:

[object HTMLBodyElement]

How can I turn it into real string?

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


Solution

  • I believe you want to use Element.outerHTML:

    console.log(content.outerHTML)