Reputation: 6485
I'm getting an odd HTML validation error from this piece of JavaScript any help appreciated, I think it may be causing a bug in the slider function that I'm working with...
<script type="text/javascript" charset="utf-8">
sfHover = function() {
var sfEls = document.getElementById("nav2").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
The errors are
Error: character ";" not allowed in attribute specification list
and
Error: element "sfEls.length" undefined
from the line
for (var i=0; i
and
Error: end tag for "sfEls.length" omitted, but OMITTAG NO was specified
from the closing script tag
Upvotes: 0
Views: 1431
Reputation: 887469
Your Javascript contains special characters for XML (<
and &
).
Therefore, it's invalid markup.
You need to wrap it in a CDATA section, which will prevent the XML parser from parsing its contents:
<script type="text/javascript">
//<![CDATA[
...
//]]>
</script>
The comments are necessary to prevent the CDATA section from causing Javascript syntax errors in browsers that don't recognize it
Upvotes: 6