How can I solve this code error when running!
var replaced = $("body").html().replace(/<td>YES</td>/g,'<span class="yes"></span>'); $("body").html(replaced);
I want to replace all
<td>YES</td>
with
<span class="yes"></span>
Consider:
$("td").filter(function() {
return $(this).text() === 'YES';
}).replaceWith('<span class="yes"></span>');
This finds all the td
elements and filters for the ones with YES
as the only contents and the replaces them.
try to use an escape character for the closing td in your expression
var replaced = $("body").html().replace(/<td>YES<\/td>/g,'<span class="yes"></span>');
$("body").html(replaced);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.