0
votes

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?

2
If you are looking up 6 ID's and want to replace them all with the same value, then its best to probably use classes. i.e add class="price" to your TD's and then use $('.price').text("coming soon"); or $('.price').html("coming soon"); [can checkout the difference] - Jason

2 Answers

1
votes

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

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

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