The following function only replaces the first “<br />” it finds, not the following ones. Does anyone know how to fix that problem?
I want the function to replace all the strings in the whole document.
<script language="javascript" type="text/javascript">
window.onload = function umtauschen()
{
document.body.innerHTML = document.body.innerHTML.replace('<br />', '<br />');
document.body.innerHTML = document.body.innerHTML.replace('<b>', '<b>');
document.body.innerHTML = document.body.innerHTML.replace('</b>', '</b>');
}
</script>
Thanks
Use regular expressions, and the
g(global) flag:Another option is to use the
.split(find).join(replace)idiom: