Replace body text conflict

Hi…Having some probs with RegExp… the replace is functioning ok, but its screwing up other js functions like form validation and password strength meter…

We think this part of the code is messing with the dom.

 var regex  = RegExp(word ,"gi");
 var string = $('body').html().replace(regex, translation);
 $('body').html(string);

is there a better way to replace text in the body?

function translate(words) { 
var language   = localStorage.getItem('language');
var parameters = {from: 'en',            
                  to: language,
                  words: words};

if (language === null) {
    language = $('#language').val();
}

$.ajax ({
    type: 'POST',
    url: 'http://bisi.bid/translate',
    datatype : "json",
    data: parameters,
    success: function(data){
        $.each(data, function(word, translation) {
            var regex  = RegExp(word ,"gi");
            var string = $('body').html().replace(regex, translation);
            $('body').html(string);
        });     
    },
    error: function() {
    }
});

}

var words = ['hello'];
translate(words);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.