简体   繁体   English

您如何呈现javascript对象?

[英]How do you render a javascript object?

I have the following javascript code, but when I try to use it on the 3rd line, I get [object HTMLHeadingElement] in the HTML output. 我有以下javascript代码,但是当我尝试在第三行使用它时,我在HTML输出中得到了[object HTMLHeadingElement] How do I take the whole HTML of x and prepend it to y.innerHTML ? 我如何将x的整个HTML y.innerHTML前面?

x = document.getElementById("region-footer-first").getElementsByClassName("block-title")[0];
y = document.getElementById("region-footer-first").getElementsByClassName("jcarousel-clip")[0];

y.innerHTML = x + y.innerHTML;

If you want the entire contents of x , including its tags, use .outerHTML , like this 如果您希望x的全部内容(包括其标签),请使用.outerHTML ,如下所示

x = document.getElementById("region-footer-first").getElementsByClassName("block-title")[0];

y = document.getElementById("region-footer-first").getElementsByClassName("jcarousel-clip")[0];

y.innerHTML = x.outerHTML + y.innerHTML;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM