2

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.

Community
  • 1
  • 1
Kuttan Sujith
  • 7,811
  • 18
  • 63
  • 92

2 Answers2

1

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');
OneOfOne
  • 88,915
  • 19
  • 172
  • 173
0

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'));
    }
 });
});
Swarne27
  • 5,411
  • 7
  • 25
  • 40