UPDATED : Please look code below:
<div class='parent'>
<div class='first'>whatever content</div>
<div class='child1'></div>
Paragraph 1
<br>
Paragraph 2
<div class='child2'></div>
<div class='child3'>whatever</div>
i don't wanna this text
<div class='last'>whatever</div>
</div>
How can I get text " Paragraph 1 Paragraph 2 " without text "I don't wanna this text" from that code?
Thank you.
NOTED : I CAN'T EDIT/CHANGE HTML CODE.
1 - How to get only a content without tags:
HTML:
<div class="parent">
<div class="first">whatever content</div>
<div class="child1"></div>
Paragraph 1
<br>
Paragraph 2
<div class="child2"></div>
<div class="child3">whatever</div>
Last Content
<div class="last">whatever</div>
</div>
JQUERY:
var content = $('.parent').clone().children().remove().end().text();
alert(content);
Demo: http://jsfiddle.net/vRbCw/3/
2- How to remove the content before div.child3:
JQUERY:
var appendSt = $('.child3').after('code:'),
content = $('.parent').clone().children().remove().end().text(),
reg = content.replace(/code:([^xyz]+)/, '');
alert(reg);
Demo : http://jsfiddle.net/sBSRH/
Get The Text Of Element Without Child Element: http://viralpatel.net/blogs/jquery-get-text-element-without-child-element/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With