alebu
Programmer
- Sep 7, 2002
- 46
Hi everyone!
When I was playing with javascript( I am new to it ), I found very interesting problem. According to w3c specification, 'document.getElementById( ID ).style' gives access to styles of object which id is ID. But in my experiments I found a very annoing restriction about this method. I found,that until style value was not set from javascript, any trying to read that style will return 'undefined' value. In other words, it is imposible to read values defined in "css" if they was not set by JS. Opera and Explorer fails absolutely the same, as twinbrothers, so thats why, I thinking that it is a limitation of w3c standart. A short example:
---css file---
.somestyle
{
visibility: hidden;
position: absolute;
top: whatever px;
}
---js file---
function dosomething()
{
var someobject= document.getElementById("someobject");
// the problem nr 1
if( someobject.style.visibility )
{
// we will never be here, until some other function set that object visibility
}
// problem nr 2 it will works only once
someobject.style.top += 40;
}
---html file which included css & js files---
<div class="somestyle" id="someobject" onmouseover="dosomething()">sometext</div>
When I was playing with javascript( I am new to it ), I found very interesting problem. According to w3c specification, 'document.getElementById( ID ).style' gives access to styles of object which id is ID. But in my experiments I found a very annoing restriction about this method. I found,that until style value was not set from javascript, any trying to read that style will return 'undefined' value. In other words, it is imposible to read values defined in "css" if they was not set by JS. Opera and Explorer fails absolutely the same, as twinbrothers, so thats why, I thinking that it is a limitation of w3c standart. A short example:
---css file---
.somestyle
{
visibility: hidden;
position: absolute;
top: whatever px;
}
---js file---
function dosomething()
{
var someobject= document.getElementById("someobject");
// the problem nr 1
if( someobject.style.visibility )
{
// we will never be here, until some other function set that object visibility
}
// problem nr 2 it will works only once
someobject.style.top += 40;
}
---html file which included css & js files---
<div class="somestyle" id="someobject" onmouseover="dosomething()">sometext</div>