如何获取元素周围的文字? [英] How to get text around an element?

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

问题描述

如果我有

<div id='wrapper'>
  <fieldset id='fldset'>
    <legend>Title</legend>
    Body text.
  </fieldset>
</div>

如何在不检索图例标记内的文本的情况下检索正文?

How could I retrieve the "Body text" without retrieving the text inside of legend tag?

例如,如果我想查看字段集中的文本是否包含单词body并更改该单词,而忽略了图例中可能存在的内容? innerHTML检索所有子节点中的所有文本。

For instance, if I wanted to see if the text inside the fieldset contains the word "body" and change that word, while ignoring whatever might be in the legend? innerHTML retrieves all text from all children nodes.

使用jQuery不会有问题。

Use of jQuery wouldn't be a problem.

推荐答案

$("#fldset").contents().eq(2).text();

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

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