How to convert the html object to string type?

hh54188 picture hh54188 · Sep 10, 2012 · Viewed 55.3k times · Source

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?

Answer

Chris picture Chris · Jul 25, 2014

I believe you want to use Element.outerHTML:

console.log(content.outerHTML)