如何获取元素后的文本节点? [英] How to get text node after element?

查看:131
本文介绍了如何获取元素后的文本节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery。
我有以下html:

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")

我也无法触摸HTML ...

I also can not touch the HTML...

推荐答案

尝试使用DOM函数 .nextSibling 选择下一个节点(包括文本节点)并使用 nodeValue 获取文字全世界

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

这篇关于如何获取元素后的文本节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆