Reputation: 1327
How to get text with html tags, but only from main DIV? Not form other DIVS.
Here is example, but there is some problem, becouse text is without html tag <br />
HTML
<div id='parent'>
this text is <br />for parent
<div id='child-parent'>
this text if for child-parent
<div id='child'>
and this text is for child.
</div>
</div>
</div>
jQuery
alert($('#parent').clone().children().remove().end().html());
Upvotes: 0
Views: 156
Reputation: 44740
Assuming child-parent
and child
will always have an id
var clone = $('#parent').clone();
clone.children().filter(function () {
return $(this).is('[id]');
}).remove();
console.log(clone.html());
Demo --->
http://jsfiddle.net/F6AeM/5/
Upvotes: 1
Reputation: 9224
I updated your fiddle and used a different tactic to remove the last element
var parent = $('#parent').clone();
$(parent).find('#child-parent').remove();
alert($(parent).html());
Not sure why this works, but yours doesn't, but here you go.
Upvotes: 1