If you want to any div text to another or many div's text to another div, then it is very simple using JQuery.
Just use the below JQuery code to append text to div.
$("#targetdivid").append($("#sourcedivid").html());
Complete example:-
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){ // on button click
$("#demo").append($("#one").html()); //append one div text to demo
$("#demo").append($("#two").html()); //append second div text to demo
$("#demo").append($("#three").html()); //append third div text to demo
});
});
</script>
</head>
<body>
<center>
<div id="one" style="border:1px solid; width:50%">This is first div tag </div>
<div id="two" style="border:1px solid; width:50%">This is second div tag </div>
<div id="three" style="border:1px solid; width:50%">This is third div tag </div>
<div id="demo" style="border:1px solid; width:20%"></div></br>
<button id="btn1">Add all div text to demo div</button>
</center>
</body>
</html>
No comments:
Post a Comment