I am trying to find and replace texts using jquery.
function replaceText() {
var jthis = $(this);
$("*").each(function() {
if(jthis.children().length==0) {
jthis.text(jthis.text().replace('nts:', 'nights:'));
}
});
}
$(document).ready(replaceText);
$("html").ajaxStop(replaceText);
here is my jsfiddle:
I need to replace the all "nts" texts on the page by "nights". Can you tell me why it's not working?
$("html").ajaxStop(replaceText);never triggered. Just put break point into beginning of replaceText function. And count how many times it called. It should be called two times. First when document is ready. Second when Ajax load completes. Another problem as others explained you should also modify replaceText function logic as one explained bellow.