This is a discussion on "new problem. document.getElementById().width returning unassigned. why?" within the JavaScript Forum section. This forum, and the thread "new problem. document.getElementById().width returning unassigned. why? are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
new problem. document.getElementById().width returning unassigned. why?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
new problem. document.getElementById().width returning unassigned. why?
Here is my js function:
function setNewsPosition() { position=document.getElementById("image_1").width;//returns value newsWidth= document.getElementById("news").width;//returns unassigned alert(position); var news= document.getElementById("news"); news.style.left= position + newsWidth + 'px'; } Here is the css part that concerns the function: div#news { float:left; width:25%; margin-left:-25%; background:#0099cc; } I first thought it is because of the percentage value, but I've switched to px and it still returned unassigned. Does anyone have a suggestion why this might be and how it could be fixed. Greetings, Valentin |
|
|
|
#2
|
|||
|
|||
|
Re: new problem. document.getElementById().width returning unassigned. why?
You can easily test what I am about to say for yourself, but I seem to remember reading somewhere that, where elements are concerned, for some reason, JavaScript will only return a width that was previously set using script. Let us know how you get on. |
|
#3
|
|||
|
|||
|
Re: new problem. document.getElementById().width returning unassigned. why?
I solved the problem.
I just used offsetWidth instead of width and it worked out fine. Thanks for your help. V |
![]() |
| Tags |
| problem, returning, unassigned |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help using document.getElementById | jonnymorris | JavaScript Forum | 3 | Mar 28th, 2008 22:52 |
| document.getElementById and document.getElementByName is not working in FF | dhineraj | JavaScript Forum | 3 | Jul 26th, 2007 20:23 |
| document.getElementById("userProfileCheck") is not working in Mozilla Firefox | dhineraj | JavaScript Forum | 1 | Jul 20th, 2007 05:32 |
| document.getElementById is not working in Mozilla Firefox | dhineraj | JavaScript Forum | 3 | Jul 20th, 2007 02:31 |
| document.getElementById[objectID].style now working on Mozilla Browser | yogeshid | JavaScript Forum | 1 | May 25th, 2007 09:30 |