John
John

Reputation: 1009

simple find & replace using jQuery

I have done a search on Google and surprisingly cannot find a relevant answer.

What I am trying to do is hook onto around 6 TD id's (id="1234price", id="2345price" etc)

and change the text within that table cell for all of them to say coming soon rather than the various prices they currently show.

looking at jquery docs replacewith seems to replace the whole thing i.e it would remove the entire td as opposed to replacing the text contained within the td?

Upvotes: 0

Views: 131

Answers (2)

Telvin Nguyen
Telvin Nguyen

Reputation: 3559

Suppose text of td look like below

<td id="price123"><a href="#">tag hyperlink</a><p>p tag</p>text</td>

Use this line

$('#price123').contents().last()[0].textContent='50';

It keeps other HTML tags on td, and change the text on the last location. Demo Change text only

Upvotes: 0

Guffa
Guffa

Reputation: 700870

Use the text method to set the text inside the elements. Example:

$('#1234price,#2345price').text("coming soon");

Upvotes: 1

Related Questions