Tech Tips
Search for Class Name
This function scan array a and returns an array of indexes to all
elements with class name cn.
<SCRIPT LANGUAGE="JavaScript">
function FindClassName(a,cn) {
r = new Array();
j = 0;
n = a.length;
for (var i=0; i < n; ++i ) {
s = a[i];
if ( s.className == cn) {
r[j] = i;
j = j + 1;
}
}
return r;
}
</SCRIPT>
Usage example: First the function is called to get an array of all
images with class name MyClass. Then one can navigate by index thru all these
images to set image img.
<SCRIPT LANGUAGE="JavaScript">
imgs = FindClassName(document.images,"MyClass");
// navigation
img.src = document.images[imgs[index]].src;
</SCRIPT>
|