i want to read an html file by using jquery get function, replace some characters then display result. I wrote get function and can replace the text. There are many rows in the table. All data inside rows displayed as text. Rows are ended with space; so iwant to replace ” ;” characters for every row. But the code below just replace the characters for the first row. How can i replace all ” ;” characters for all rows?
$.ajax({
url: 'http://url',
type: 'GET',
success: function(data) {
var def = $(data).find('tbody#div.divWord').html();
$('#def').append('<p><b>' + word + '</b>:' + def + '</p>');
$("div").each(function() {
var text = $(this).text();
text = text.replace(" ;", "@");
$(this).text(text);
});
},
error: function(data) {
alert('error');
}
});
the Replace function only matches the first result by default.
If you want to replace every occurence, you have to take a regular expression and set the “global flag”:
or
where
\smatches Whitespace Characters.or