javascript getElementById and convert it to String

javascript

Solution

If you want a string representation of the entire tag then you can use `outerHTML` for browsers that support it:

var someElementToString = someElement.outerHTML;

For other browsers, apparently you can use XMLSerializer:

var someElement = document.getElementById("id");
var someElementToString;

if (someElement.outerHTML)
    someElementToString = someElement.outerHTML;
else if (XMLSerializer)
    someElementToString = new XMLSerializer().serializeToString(someElement); 

Problem

is there a way to convert a javascript HTML object to a string? i.e. ``` var someElement = document.getElementById("id"); var someElementToString = someElement.toString(); ``` thanks a lot in advance

Original source

Related problems