开发者

document.getElementById("images").children[0] to a string

开发者 https://www.devze.com 2023-02-05 20:57 出处:网络
The toString() method will output [object HTMLImageEle开发者_StackOverflow中文版ment]. I want a string representation of the the image element \'<img src=\"...\" />\'. outerHTML returns undefine

The toString() method will output [object HTMLImageEle开发者_StackOverflow中文版ment]. I want a string representation of the the image element '<img src="..." />'. outerHTML returns undefined in firefox.

How can I accomplish this?


outerHTML is not cross-browser.

The easiest way is to clone the element and add it to a parent element, then get the innerHTML of that:

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

outer.appendChild(child);

var imgHtml = outer.innerHTML;
0

精彩评论

暂无评论...
验证码 换一张
取 消