Reputation: 26587
I need to do a copy of html inside one div to another div such that it shows the latest html content at any time. The content in duplicate div should change when original is changed.
I'm using jquery. How do I do that ?
EDIT: Need to do that live.
Upvotes: 2
Views: 1475
Reputation: 30135
You could do the bruteforce method by polling the content of the first div and copy it if it changed:
html:
<div id="d1">some stuff</div>
<div id="d2"></div>
js:
setInterval(function(){
if($('#d1').html()!=$('#d2').html()){
$('#d2').html($('#d1').html());
}
},1000);
this checks every second.
If you have a callback or event when you know the content of div1 changed, then you could copy the content only then. This would be more efficient of course.
Upvotes: 9