new problem. document.getElementById().width returning unassigned. why?

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.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jul 21st, 2006, 23:55
Junior Member
Join Date: Jul 2006
Location: Sofia, Bulgaria
Age: 22
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 22nd, 2006, 20:21
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 22nd, 2006, 20:23
Junior Member
Join Date: Jul 2006
Location: Sofia, Bulgaria
Age: 22
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
problem, returning, unassigned

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 05:50.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42