jquery - 使用 jQuery 查找具有特定文本(值)的子元素

标签 jquery find element

我有一棵树,位于 <div> 内标签(id:treePanel)。 这棵树实际上是一堆<ul> and <li>嵌套在多个级别中的标签( <ul> 标签位于另一个 <ul> 标签内,依此类推。

我需要在这棵树中找到一个具有特定文本的节点(<li> 标签之一)并更新它。我怎样才能使用 jQuery 做到这一点?

示例:

<div id="treePanel">
<ul>
  <li> root 1</li>
  <li> root 2</li>
  <li> root 3
  <ul>
    <li> leaf1</li>
    <li> leaf2</li>
    <li> find me</li>
  </ul>
  </li>
</ul>
</div>

最佳答案

I need to find a node in this tree (one of the tags) that has a specific text and update it

使用:contains Docs 过滤器选择器:

$('#treeID li:contains("your text")').......

关于jquery - 使用 jQuery 查找具有特定文本(值)的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8253053/

相关文章:

java - 如何获取字符串数组中元素的长度(出现错误)?

jquery - 后伸 100% div 高度

php - 如何将 Bootstrap Modal 中的数据添加到 MySQL

javascript - 保持可缩放图像的纵横比

javascript - 单选按钮在开发控制台中显示为未定义

jQuery显示:after when certain DIV is found in document中的内容

jquery - 使用 JS/jQuery 查找字母顺序错误的单词

javascript - Lodash _.find 在参数中使用变量不起作用

javascript - 如何获取具有多个类的元素

dom - 如何访问 d3 SVG 元素的数据