Home Page DOM Tutorials Dynamic Text The gloss() function |
We first create a list of the English translations for each glossary term. A list of Spanish words isn't necessary; we'll see why later.
vocabList = new Array( "source", "obtain", ... "by means of", "through (by means of)" );
We use this array in the gloss() function, which is shown below. The line numbers are just for reference in the explanation.
1 function gloss( evt ) 2 { 3 var defnList = document.getElementById( "dlist" ); 4 var defnTerm = document.getElementById( "dterm" ); 5 var defnData = document.getElementById( "ddefn" ); 6 var glossDiv = document.getElementById( "glossDiv" ); 7 var instrDiv = document.getElementById( "instructionDiv" ); 8 var fullDiv = document.getElementById( "fullDiv" ); 9 var owner = findOwner( evt ); 10 var spanId = owner.attributes.getNamedItem("id").nodeValue; 11 12 spanId = parseInt( spanId.substr(1)); 13 14 instrDiv.style.display = "none"; 15 fullDiv.style.display = "none"; 16 17 defnTerm.replaceChild( 18 document.createTextNode( evt.target.data ), 19 defnTerm.firstChild ); 20 21 defnData.replaceChild( 22 document.createTextNode( vocabList[spanId] ), 23 defnData.firstChild ); 24 25 glossDiv.style.display = "block"; 26 }
Modifying a Node | Index | A Philosophical Interlude |