Beer
<br>
Vodka
<br>
rum
<br>
whiskey
how can you select beer ? or rum ? in jquery ? they are not surrounded by any html tags….
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you mean that you want to select the text node directly, this is advised against using jQuery. To clarify, getting a wrapped set of text nodes is not a problem, but chaining commands onto a wrapped set of text nodes has unpredictable results or does not work with many of the commands since they expect the wrapped set to contain element nodes.
You can do it by filtering the children of a parent to return only text nodes, i.e.
nodeType === 3but if your question is about performing some manipulation on the text, then get the parent element and manipulate the text contents. For example,If you wanted to get the text nodes, the following is one way
Or you may want to look at Karl Swedberg’s Text Children plugin, which provides various different options too.
EDIT:
In response to your comment, one way to work with the text nodes in a wrapped set is to convert the jQuery object to an array, then work with the array. For example,