Adi K.: Verwendung im Source Code

Beitrag lesen

Weiter unten steht der Source-Code, wo ich den Array gebraucht hätte. Ich habe es nun mit Hilfe des Tipps von KurtZ (Danke!) realisiert, finde aber die Methode nicht besonders elegant. Meine Frage ist deshalb immernoch aktuell:
Kann man Knotenobjekte irgendwie als Index eines Arrays brauchen?

Gruss,
Adi

PS: Ich meinte natürlich getElementById('x')

----

  
/*  
 * Cell Clicker v1.0  
 * (C) Adrian Kousz 2007  
 * Released under the terms of the LGPL 3  
 * http://www.gnu.org/licenses/lgpl.html  
 *  
 * Embedding:  
 * In header: <script type="text/javascript" src="CellClicker2.js"></script>  
 * At the end of body: <script>makeClickable()</script>  
 */  
  
var clickClass = 'ic'; // the class name of the clickable element  
var hoverColor = 'black';  
  
var correl = new Array();  
function makeClickable() {  
    var inputs = new Array();  
    var curr;  
    var button;  
    inputs = document.getElementsByTagName('input');  
    for (var i=0;i<inputs.length;i++) {  
        curr = inputs[i];  
        if (curr.type == 'radio' || curr.type == 'checkbox') {  
            if (button = findClickable(curr)) {  
                button.correl = (Math.random()*1000000).toFixed(0);  
                correl[button.correl] = curr;                // <- Die temporäre Lösung  
                button.onmouseover = function() {normalColor = this.style.backgroundColor; this.style.backgroundColor = hoverColor}  
                button.onmouseout = function() {this.style.backgroundColor = normalColor}  
                button.onclick = function() {correl[this.correl].checked = !correl[this.correl].checked}  
                curr.onclick = function() {this.checked = !this.checked}  
            }  
        }  
    }  
}  
  
function findClickable(e) {  
    var n = e;  
    while (n.className != clickClass && n.nodeType != 9) {n = n.parentNode}  
    if (n.nodeType == 9) {return undefined}  
    else {return n}  
}