I am trying to do a search and replace of text that has the same name inside the body
but it is partial working, some of the text is being replace, but then some of the old text still show up, not quite sure what is going on.
$(document).ready(function() {
$('*').each(function(){
if($(this).children().length == 0)
$(this).text($(this).text().replace("old text", "replace with new text"));
});
});
much help is appreciated
thanks
Use the
:containspseudo-class selector to find any elements containing that text, then replace from there.If you know a list of elements that you’d like to target, another solution would be to first find those elements, then filter over them using :contains.