To bolster my argument about how, as things become more complex, they begin to become easier using the DOM:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div id="maincontainer">something</div>
<script type="text/javascript">
function VirtualWindows() {
var vwindows = new Object();
var maincont = document.getElementById('maincontainer');
this.cr = function(el, txt, id, evt){
var e = document.createElement(el); if(id) e.id = id;
if(txt) e.appendChild( document.createTextNode(txt) );
if(evt) e[evt.ev] = evt.f; return e;
};
this.make = function(el, txt, tp) {
var componentindex=0;
for (var prop in vwindows) componentindex++;
var windowid = 'window'+componentindex;
var nNode = this.cr('div', '', windowid, {ev:'onclick', f:function(){alert('ready to boogy #'+componentindex);}});
with (nNode.style){border='1px solid red';width='50px';height='50px';position='absolute';
top=tp+'px';left='100px';backgroundColor='#ccc';};
nNode.appendChild( this.cr(el, txt) );
maincont.appendChild(nNode);
vwindows[windowid] = nNode;
};
this.showContent = function() {
var temp = '';
for (var prop in vwindows) {
temp += '#'+prop+'-'+vwindows[prop].innerHTML + ' onclick-'+vwindows[prop].onclick+'\n';
}
alert(temp);
};
}
var vw = new VirtualWindows();
vw.make('span', 'asldfjdas', 50);
vw.make('div', 'asdölfkj', 200);
vw.make('div', 'öalskdj fpoiasd' ,500);
vw.showContent();
</script>
</body>
</html>
Bookmarks