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?
To convert a HTMLElement to a string with JavaScript, we can use the outerHTML property. const element = document. getElementById("new-element-1"); const elementHtml = element.
We can convert Object to String in java using toString() method of Object class or String. valueOf(object) method. You can convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer or anything else.
Stringify a JavaScript ObjectUse the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);
The answer is option D (str(x)). str(x) converts the object to a string in python.
I believe you want to use Element.outerHTML:
console.log(content.outerHTML)
I had the same problem.
var docString = "<html>"+content.documentElement.innerHTML+"</html>"
You can use this content[0].prop('outerHTML')
It worked for me
Reference : How do you convert a jQuery object into a string?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With