i like to clone a table and remove the word EUR from each cell. I tried with .removeByContent but got the error "is not a function".
This is my code:
var cln = $('#tableid').clone();
cln.find('.noExl').remove();
cln.removeByContent('EUR');
And this is the table:
<table id="tableid"><tr><td>Bacon</td><td>140 EUR</td></tr><tr><td>Ham</td><td>70 EUR</td></tr></table>
How can i remove a String in the cloned element?
You can loop through tds and then use replace("EUR", "")
to replace EUR
text from tds .
Demo Code :
var cln = $('#tableid').clone();
//find tds in cloned htmls
cln.find("td").each(function() {
//replace text with ""
$(this).text($(this).text().replace("EUR", "").trim())
})
$(cln).appendTo($("#new_ids"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="tableid" border="1">
<tr>
<td>Bacon</td>
<td>140 EUR</td>
</tr>
<tr>
<td>Ham</td>
<td>70 EUR</td>
</tr>
</table>
<div id="new_ids"></div>