Reputation: 3
i need to replace the content of one div whit the content of another.
i have something like this <div><span>texta</span></div>
and i need to replace with the content of another div in the page.
How do i replace the content of a div with jquery?
Upvotes: 0
Views: 1310
Reputation: 51201
There is a cool website, named jQuery.com with a feature called Documentation where you can read a lot of cool stuff on manipulating your "HTML":
http://api.jquery.com/category/manipulation/
edit: to make this a little less troll-like, try the following:
var stuff = $('<your-element>').clone();
$('<the-other-element>').html(stuff);
Upvotes: 2
Reputation: 6106
<div>
<div id="div1">
<span>content 1</span>
</div>
<div id="div2">
<span>content 2</span>
</div>
<div>
<script type="text/javascript">
$(function() {
$("#div1 span").html( $("#div2 span").html() );
});
</script>
see it work here: http://jsfiddle.net/harpax/P7EZw/
Upvotes: 0
Reputation: 2924
suppose you have div like this...
<div align="center" id="divId">
</div>
to change content ..
$('.click').click(function() {
// get the contents of the link that was clicked
var linkText = $(this).text();
// replace the contents of the div with the link text
$('#divId').html(linkText);
// cancel the default action of the link by returning false
return false;
});
Upvotes: 2