问题
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 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?
回答1:
I believe you want to use Element.outerHTML:
console.log(content.outerHTML)
回答2:
I had the same problem.
var docString = "<html>"+content.documentElement.innerHTML+"</html>"
回答3:
You can try the following:
content.text();
回答4:
You can use this content[0].prop('outerHTML')
It worked for me
Reference : How do you convert a jQuery object into a string?
回答5:
The correct way to Convert a jQuery object into a string:
var content = $('#cke_ckeditor').find('.cke_show_borders').eq(0).clone();
console.log(content.get(0).outerHTML);
来源:https://stackoverflow.com/questions/12344832/how-to-convert-the-html-object-to-string-type