I want to highlight a word within a div when page will be loaded. My code is
<script type="text/javascript">
function highlight(container,what,spanClass) {
var content = container.innerHTML,
pattern = new RegExp('(>[^<.]*)(' + what + ')([^<.]*)','g'),
replaceWith = '$1<span ' + ( spanClass ? 'class="' + spanClass + '"' : '' ) + '">$2</span>$3',
highlighted = content.replace(pattern,replaceWith);
return (container.innerHTML = highlighted) !== content;
}
</script>
</head>
<body onload="highlight(document.getElementById('hello'),'florida','highlight');">
<div id="hello"> Florida florida orlando orlando</div>
Florida Texus florida
</body>
</html>
And nothing is happening in FF/Chrome/IE. I need your advice to fix this.