How to get text node after element?

Itay Moav -Malimovka picture Itay Moav -Malimovka · Oct 22, 2012 · Viewed 24.4k times · Source

Using jQuery. I have the following html:

<input type="checkbox" name='something' value='v1' /> All the world <br />

How would I get ONLY the text. what selector should I use? (I need the "All the world")

I also can not touch the HTML...

Answer

Selvakumar Arumugam picture Selvakumar Arumugam · Oct 22, 2012

Try using the DOM function .nextSibling to pick the next node (including the text nodes) and use nodeValue to get the text All the world

$(':checkbox')[0].nextSibling.nodeValue