JQuery Select text outside / next to child

Just getting to know jquery, please consider me as a noob.

I am trying to select text in this following scenario: -

<div id="blah">
<p> <span>Text1</span> text2</p>
</div>

How can I get the value of text2?

thank

+5
source share
1 answer

If you want the text of the entire tag to puse:

var text = $("#blah p").text();

Otherwise, if you want to exclude the part span, use:

var text = $("#blah p").contents(":not(span)").text();

Now your text will be saved in a variable named text.

+6
source

All Articles