Document.getElementById ("images"). children [0] per line

The toString () method will return [object HTMLImageElement]. I want a string representation of an image element '<img src="..." />'. outerHTML returns undefined in firefox.

How can i do this?

+3
source share
1 answer

outerHTML is not inter-server.

The easiest way is to clone an element and add it to the parent element, and then get innerHTMLfrom this:

var outer = document.createElement('outer'),
    child = document.getElementById("images").children[0].cloneNode(true);

outer.appendChild(child);

var imgHtml = outer.innerHTML;
+11
source

Source: https://habr.com/ru/post/1787029/


All Articles