Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a child element with specific text (value) using jQuery

I have a tree that is inside a <div> tag (id: treePanel). This tree is actually a bunch of <ul> and <li> tags that are nested in several levels (<ul> tag inside another <ul> tag and so on.

I need to find a node in this tree (one of the <li> tags) that has a specific text and update it. How can I do this using jQuery?

Example:

<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>
like image 792
Aref Avatar asked Nov 24 '11 06:11

Aref


1 Answers

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

Use :contains Docs filter selector:

$('#treeID li:contains("your text")').......
like image 83
Sarfraz Avatar answered Sep 21 '22 12:09

Sarfraz