I have this structure:
<table id="thetable">
<tr>
<td>
<div>
<div>some text</div>
<div>
<div></div>
<div>(This text is good)</div>
<div>some text2</div>
<div>some text3</div>
</div>
</div>
</td>
<tr>
</tr>
<td>
<div>
<div>some text</div>
<div>
<div></div>
<div>(This text is good)</div>
<div>some text2</div>
<div>some text3</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div>
<div>some text</div>
<div>
<div></div>
<div>(This text is good)</div>
<div>some text2</div>
<div>some text3</div>
</div>
</div>
</td>
</tr>
</table>
I want to take the text inside the div, but only the text with this word: good. and replace. So I do this:
$("#thetable div:contains('good')").each(function () {
try {
console.log($(this).text());
console.log("------------------------------");
} catch (ex) {
}
})
But console.log tells me that every log accepts not only div text with good text, but also two others. This is the seal:
(This text is good)some text2some text3
So, I want to use only div with text and replace this text with another text.
Thank!
Basically: I want to get a div where I have the word "good" (or any word I want), and insert / replace text in this div. Find in the entire document or, in particular, in part of the document, for example, in this example: in the table.
source
share