This is part ten of a series on Dynamic HTML
Binding Javascript to the DIV:
Associating Javascript objects to the browsers' <DIV> objects is one of the most important steps in creating DHTML code. In javascript , you can assign new variables and or functions to most existing objects, even those representing HTML layers.
Binding to layer objects
You can bind to layer objects using the following code example:
// *** This line merges the syntax for cross-browser references to layers
if(!document.all)if(document.layers)document.all=eval('document.layers')
if(!document.all)if(document.getElementsByTagName)
document.all=getElementsByTagName('div')
// *** This declares a simple binding object
// that makes an association between the HTML layer and javascript
function DCbindTo(layerName)
{
this.jsLAYERobject=document.all[layername]
this.jsLAYERobject.Homeboy=this;
if(!document.all[layername].style)
document.all[layername].style=document.all[layername];
}
Next, we get into Event handling.