I'm just diving into the world of JavaScript and have put together a little fiddle with my code. Check it out here.
However, I've run into an issue where removing CDATA makes it work fine in fiddle but causes problems in XHTML editors like Eclipse:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Below is a snippet of my JavaScript:
<![CDATA[
function test() {
alert(document.getElementById("divId"));
var regex = new RegExp('this',"gi");
document.getElementById("divId").innerHTML
= document.getElementById("divId").innerHTML.replace(regex,
function(matched)
{
return '<span class=\'highlight\'>' + matched + '</span>';
});
}
]]>
This is the <div>
causing me trouble:
<div id="divId">
This is the text This is the text This is the text This is the text
This is the text This is the text This is the the text
</div>
Unfortunately, I can't seem to call the test()
function. Any advice on how to proceed?