If I click on #parent I want to return the text inside it and not return the text inside nested
layers (#child-parent, #child)
<div id='parent'>
this text is for parent
<div id='child-parent'>
this text if for child-parent
<div id='child'>
and this text is for child.
</div>
</div>
</div>
this:
$('#parent').html() = "this text is for parent"
and not this:
$('#parent').html() = "this text is for parent this text is for child-parent and this text is for child"
You can grab it like this:
You can test it out here, you may want a
$.trim()call on there though, like this.Another alternative is to loop though the text nodes, like this:
You can test that here or the trimmed version here.