如何将html对象转换为字符串类型?

hh5*_*188 17 string html-parsing

我使用jQuery方法来获取某些类型的html对象:

var content = $('#cke_ckeditor iframe').contents().find('.cke_show_borders').clone();
Run Code Online (Sandbox Code Playgroud)

然后我想将其转换为string类型:

console.log(content[0].toString());
Run Code Online (Sandbox Code Playgroud)

但结果是:

[object HTMLBodyElement]
Run Code Online (Sandbox Code Playgroud)

我怎样才能把它变成真正的字符串?

顺便说一下,我可以将转换后的html字符串转换为html对象吗?

Chr*_*ris 28

我相信你想使用Element.outerHTML:

console.log(content.outerHTML)