We would like to know how to replace string in element html content.
<!--from ww w. j a v a 2 s . c o m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){
var elements = document.getElementsByClassName('test1');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = elements[i].innerHTML.replace('foo', 'bar')
};
}
</script>
</head>
<body>
<span class="test1">foo</span>
<br />
<span class="test1">foo</span>
</body>
</html>
The code above is rendered as follows: