Reputation: 6085
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.
Upvotes: 3
Views: 9218
Reputation: 1
<html>
<head>
<script>
function change() {
document.getElementById('demo1').innerHTML = document.getElementById('demo').innerHTML;
}
</script>
</head>
<body>
<div class="left">
<input type="text" id="demo" value="hi" />
<input type="button" onClick="change()" />
</div>
<div class="right">
<p id="demo1"></p>
</div>
</body>
</html>
Upvotes: -1
Reputation: 24606
Using jQuery:
$("#div2").html($("#div1").html());
You can trigger this with a click() handler on the button:
$("#copy").click(function() {
$("#div2").html($("#div1").html());
});
Upvotes: 5
Reputation: 18177
<div id="div1">Some Content</div>
<div id="div2"></div>
<input type="button" onclick="document.getElementById('div2').innerHTML=document.getElementById('div1').innerHTML"/>
Upvotes: 5
Reputation: 5608
<input type="button" onclick="document.getElementById('div2').innerHTML = document.getElementById('div1').innerHTML" value="Copy" />
Upvotes: 4