tags:

views:

48

answers:

3

I have div1 and div2, upon clicking copy button I want the text in div1 copied to div2, how is it possible in javascript, pls help.

+4  A: 

<input type="button" onclick="document.getElementById('div2').innerHTML = document.getElementById('div1').innerHTML" value="Copy" />

TheBrain
A: 

Using jQuery:

$("#div2").html($("#div1").html());

You can trigger this with a click() handler on the button:

$("#copy").click(function() {
    $("#div2").html($("#div1").html());
});
Nathan Taylor
Downvote? Is there something wrong with this solution?
Nathan Taylor
Probably due to relying on jQuery opposed to pure Javascript per the original question, but that's just a guess.
The Moof
Accepted with 2 upvotes and 2 downvotes... Critics everywhere.
Nathan Taylor
+4  A: 
<div id="div1">Some Content</div>
<div id="div2"></div>
<input type="button" onclick="document.getElementById('div2').innerHTML=document.getElementById('div1').innerHTML"/>
jigfox