First, forget the word id. Classes and id's are two separate beasts. The easy way to recall the difference? An id refers to ONE and only ONE object. A class can be a billion objects, if you were really that needy. :P
Your current code:
Code:
<script type="text/javascript" src="scripts/getElementsByClassName-1.0.1.js"></script>
<script type="text/javascript">
function toggle_visibility(className) {
var e = getElementsByClassName(className),
var f = document.getElementById(className);
for ( var i=0, len=e.length; i<len; ++i ){
if(e[i].style.display == 'none')
{
e[i].style.display = 'block';
f[i].style.background='url(graphics/*className*.gif';
}
else
{
e[i].style.display = 'none';
f[i].style.background='none';
}
}
}
</script>
Basically, like I said above, you don't need f. An id does not exist here. I fixed the syntax, however, I'm not 100% sure if the background will work as intended. I'm not testing it at the moment.
Code:
<script type="text/javascript" src="scripts/getElementsByClassName-1.0.1.js"></script>
<script type="text/javascript">
function toggle_visibility(className) {
var e = getElementsByClassName(className);
for ( var i=0, len=e.length; i<len; ++i ){
if(e[i].style.display == 'none'){
e[i].style.display = 'block';
e[i].style.background='./graphics/' + className + '.gif';
}
else{
e[i].style.display = 'none';
e[i].style.background= '';
}
}
}
</script>
Bookmarks