K Bob
K Bob

Reputation: 39

Javascript: How to switch div content?

Using an onclick function, I'm trying to take the content from a hidden div, and place it into a visible div. Instead of the content showing up, I get [object HTMLDivElement] instead. How do I fix that?

My code:

function infoclick1(){
    var x = document.getElementById('HIDE1');
    document.getElementById('moreinfo').innerHTML = x;
}

Upvotes: 1

Views: 1463

Answers (2)

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

function infoclick1(){
    var x = document.getElementById('HIDE1').innerHTML;
    document.getElementById('moreinfo').innerHTML = x;
}

Working Example: http://jsfiddle.net/WK8sW/

Upvotes: 2

Joe
Joe

Reputation: 15812

You want to set it to x's innerHTML, so

document.getElementById('moreinfo').innerHTML = x.innerHTML;

Upvotes: 1

Related Questions