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,889
  • 18
  • 64
  • 95

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
  • 95,033
  • 20
  • 184
  • 185
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,521
  • 7
  • 26
  • 41