Possible Duplicate:
Jquery: Find Text and replace
I am Using latest jQuery library with html.I want to replace all occurrences of text "Cat" with "Man" in an whole html file using jQuery, exactly the word only case sensitively.
Possible Duplicate:
Jquery: Find Text and replace
I am Using latest jQuery library with html.I want to replace all occurrences of text "Cat" with "Man" in an whole html file using jQuery, exactly the word only case sensitively.
Hmm..
jQuery Version :
$('body').html($('body').html().replace(/\bCat\b/g, 'Man'));
Pure JavaScript version :
document.body.innerHTML = document.body.innerHTML.replace(/\bCat\b/g, 'Man');
Try this to replace the words in the <title>
tag even because when you say whole html file those also are included,
$(document).ready(function(){
$("*").each(function () {
if ($(this).children().length == 0) {
$(this).text($(this).text().replace('Cat','Man'));
}
});
});