简体   繁体   中英

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. How do I take the whole HTML of x and prepend it to 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 = 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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