JQuery InnerText不包括子元素 [英] JQuery InnerText not including sub element
本文介绍了JQuery InnerText不包括子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在不获取其子项文本的情况下获取嵌套列表项的文本,即
Im wondering how I would get the text of a nested list item without getting the text of its children i.e.
<ul>
<li id="node">
I want this
<ul>
<li>
I dont want this
</li>
</ul>
</li>
</ul>
现在使用jquery和$('#node')。text()获取所有文本,其中因为我只想要我想要这个字符串。
Now using jquery with $('#node').text() gets me all text, where as I just want the "I want this" string.
任何帮助表示赞赏。
干杯,克里斯。
推荐答案
有一个 Text Children Plugin ,如果这是你想经常做的事情。它还为您提供了一些输出选项。
There's a Text Children Plugin for this, if it's something you'll want to do often. It offers you a few options for the output too.
这篇关于JQuery InnerText不包括子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文