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
2010-08-13 09:54:11
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
2010-08-13 09:54:50
Downvote? Is there something wrong with this solution?
Nathan Taylor
2010-08-13 10:12:52
Probably due to relying on jQuery opposed to pure Javascript per the original question, but that's just a guess.
The Moof
2010-08-26 21:24:13
Accepted with 2 upvotes and 2 downvotes... Critics everywhere.
Nathan Taylor
2010-09-11 22:57:49
+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
2010-08-13 09:55:33