I am trying to do some optimized unobtrusive scripting. Basically creating a script that allows me to switch classes on a series of elements. It works perfectly in Firefox, but ALL OTHER browsers are ignoring my script completely. I’ve gone over it with a fine tooth comb, not that it is such a large script anyway, but I am a bit of a noob and I must be missing something stupid. a typo? a declaration that FF forgives but that other browsers cant live w/o? Am at a loss … suggestions are greatly appreciated:
<style type=“text/css”>
ul{width:25%}
li{ list-style-position:inside}
li *:first-child {display:inline;}
li:hover{background: pink}
</style>
<script type=“text/javascript”>
function foo(ids , els){
IDcount=ids.length;
for (a=0; a< IDcount; a++){
curEL=els[a];
curID=document.getElementById(ids[a]);
children=curID.getElementsByTagName(curEL);
childCount=children.length;
for (i=0; i< childCount; i++){
children[i].OnMouseOver=function(){ plusClass("over",this);};
children[i].OnMouseOut=function(){ minusClass("over",this);};
}
}
}
function plusClass(class, eli){
eli.className+=" "+class;
}
function minusClass(class, eli){
oldclass=eli.className;
class2=" "+class;
if (oldclass.indexOf(class2)>-1){ newclass=eli.className.replace(class2,""); eli.className=newclass;}
}
</script>
<style type=“text/css”>
.over{color:red}
</style>
</head>
<body onLoad=“f<h2></h2>oo”>
<ul id="name">
<li>
<p>lorem ipsum something something. </p>
<p>lorem ipsum something something. </p>
</li>
<li>
<p>lorem ipsum something something. </p>
</li>
<li>
<p>lorem ipsum something something. </p>
<p>lorem ipsum something something. </p>
</li>
<li>
<p>lorem ipsum something something. </p>
</li>
<li>
<p>lorem ipsum something something. </p>
<p>lorem ipsum something something. </p>
<p>lorem ipsum something something. </p>
</li>
</ul>
<script type=“text/javascript”>
var IDlist= new Array(“name”);//IDs to watch go in the parentehsis
var ELlist= new Array(“LI”);//corresponding elements go in the parentehsis
foo(IDlist, ELlist);
</script>
</body>
</html>