Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Select text outside/next to a child

Tags:

jquery

select

just getting myself familiar with jquery, please consider me as a noob for now.

I am trying to select text in this follow scenrio:-

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

How can I get the value of text2 ?

Thank you

like image 512
HeWhoProtects Avatar asked Mar 20 '12 22:03

HeWhoProtects


1 Answers

If you want the text of entire p tag use:

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

Otherwise if you want to exlude the span part, then use:

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

Your text will now be stored in the variable named text.

like image 164
d_inevitable Avatar answered Oct 19 '22 23:10

d_inevitable