Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getElementById(ID).style.<anything> is undefined while not set by JS 2

Status
Not open for further replies.

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>
 
Thanks, it was very useful!
Conclusion I made consists of good and bad parts:
Good is that there IS solution, and bad is WHAt kind of solution it is! I really dissapointed in w3c this time...
 
theboyhope

I think I'll give you another star for that old post. That one REALLY helped me out a lot, and I've reused that info many times.

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top