Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get text node after element?

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...

like image 295
Itay Moav -Malimovka Avatar asked Oct 22 '12 18:10

Itay Moav -Malimovka


People also ask

How do I get nodes in text?

To get the text node of an element with JavaScript, we can use the document. createNodeIterator method to iterate through all the text nodes. to select the p element with document. querySelector .

How do I get text from an element?

Use the textContent property to get the text of an html element, e.g. const text = box. textContent . The textContent property returns the text content of the element and its descendants. If the element is empty, an empty string is returned.

How do you append after an element?

First, select the ul element by its id ( menu ) using the getElementById() method. Second, create a new list item using the createElement() method. Third, use the insertAfter () method to insert a list item element after the last list item element.


1 Answers

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 
like image 87
Selvakumar Arumugam Avatar answered Sep 23 '22 03:09

Selvakumar Arumugam