rangana
05-13-2008, 09:15 AM
Good Day!,
I've been trying to find answer on this script why it works:
<script type="text/javascript">
window.onload=function()
{
var obj=document.getElementById('toggle');
var obj2=document.getElementById('toggle2');
obj.style.textDecoration='underline';
obj2.style.textDecoration='underline';
disp.style.display='none'; //Error here
disp2.style.display='none'; //Error here
obj.onclick=function()
{disp.style.display=(disp.style.display!='none')?'none':'';}
obj2.onclick=function()
{disp2.style.display=(disp2.style.display!='none')?'none':'';}
}
</script>
<span id="toggle">Link1</span><br>
<div id="disp">
Link2<br>
Link3<br>
Link4<br>
Link5<br>
Link6<br>
Link7<br>
Link8<br>
Link9<br>
Link10<br>
Link11<br>
</div>
<span id="toggle2">LinkMe</span><br>
<div id="disp2">
link1
link2
link3
</div>
LinkYou<br>
LinkAgain<br>
...as you can see, i've commented that part where I'm expecting an error:
disp.style.display='none'; //Error here
disp2.style.display='none'; //Error here
I haven't declared disp nor disp2 yet...and for whatever reason, both IE and FF does'nt throws error, which confused me :confused:
Could someone please shed some light, as I'm totally confused.
I checked this script with DTD (http://alistapart.com/ariticles/doctype) and does throws an error, but then, I would want to know the logic behind why this one works, without a DTD :o
I've been trying to find answer on this script why it works:
<script type="text/javascript">
window.onload=function()
{
var obj=document.getElementById('toggle');
var obj2=document.getElementById('toggle2');
obj.style.textDecoration='underline';
obj2.style.textDecoration='underline';
disp.style.display='none'; //Error here
disp2.style.display='none'; //Error here
obj.onclick=function()
{disp.style.display=(disp.style.display!='none')?'none':'';}
obj2.onclick=function()
{disp2.style.display=(disp2.style.display!='none')?'none':'';}
}
</script>
<span id="toggle">Link1</span><br>
<div id="disp">
Link2<br>
Link3<br>
Link4<br>
Link5<br>
Link6<br>
Link7<br>
Link8<br>
Link9<br>
Link10<br>
Link11<br>
</div>
<span id="toggle2">LinkMe</span><br>
<div id="disp2">
link1
link2
link3
</div>
LinkYou<br>
LinkAgain<br>
...as you can see, i've commented that part where I'm expecting an error:
disp.style.display='none'; //Error here
disp2.style.display='none'; //Error here
I haven't declared disp nor disp2 yet...and for whatever reason, both IE and FF does'nt throws error, which confused me :confused:
Could someone please shed some light, as I'm totally confused.
I checked this script with DTD (http://alistapart.com/ariticles/doctype) and does throws an error, but then, I would want to know the logic behind why this one works, without a DTD :o