0

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;
1
  • 1
    One does not simply render an object. Commented Jan 13, 2014 at 22:45

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

7 Comments

but i'm only grabbing the HTML inside that. I want the entire x output added to y.
What do you mean when you say 'the entire x output'
Did you mean outerHTML?
@duckx - x.outerHTML
@Derek朕會功夫 haha whoops. Thanks for catching that
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.