hey guys im a ajax request to get selected words so that i can then translate the text in my page...but while trying to replace text which works it effects every other script from working like my form validation, password strength meter etc...
- 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);
i think that this part of the code is effecting 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?
thank you