开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜