I am attempting to change all instances of a given word on a page to another word. With the script I am using now, the word is changed, but then the javascript is displayed as well. What am I doing wrong?
<html>
<head>
</head>
<body>
This is a test of finding a word and changing it.
</body>
<script type="text/javascript" src="jquery-2.1.4.min.js"></script>
<script type="text/javascript">
var $els = $(document.body);
$els.each(function(){
$(this).html($(this).text().replace(/word/g, 'banana'));
});
</script>
</html>
It's rendered as:
This is a test of finding a word and changing it. var $els = $(document.body); $els.each(function(){ $(this).html($(this).text().replace(/banana/g, 'banana')); });