473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Handle dynamic properties of DIVs

I started developing a website that for many aspects should be similar
to a Flash website but of course only in JS. What a challenge! An
important part, of course, should be the managing of the position of
the objects and to do so I need at least to be able to get all the
properties from them, also if they have dynamic content. The very
simple issue I'm stuck at the moment is to get the width of a div that
contain a text, to place at its right the next div. I have very
different behaviors in IE and Mozilla when I move a DIV. In fact given
this structure:

<div name="containerDiv" id="containerDiv"
style="background-color:#CCCCCC;position:absolute;top:10px;left:10px ">
<div name="levelZeroDiv" id="levelZeroDiv">
some text here...
</div>
<div name="levelOneDiv" id="levelOneDiv"
style="background-color:#CC0000;position:absolute;top:0px;"></div>
</div>

after using this code (it is very simplified from the original):

document.getElementById('levelOneDiv').innerHTML=" some text here...";
getStyleObject("levelOneDiv").left= "100px";

on IE I have the DIV with its colored background placed to the right
position, on Mozilla I see the text positionate in the right position
but no backround. The left attribute seems the be changed but if I
check its width, using this function I refined from one I found on the
web:

function getWidth(someObject){
var w;
if (someObject.style.width){
w=someObject.style.width;
}else if(someObject.style.pixelWidth){
w=someObject.style.pixelWidth;
}else if(someObject.offsetWidth){
w=someObject.offsetWidth;
}else if(document.defaultView &&
document.defaultView.getComputedStyle) {
w=document.defaultView.getComputedStyle(someObject ,'').getPropertyValue('width');
}
if(typeof w=="string") w=parseInt(w);
return w;
}

getWidth(document.getElementById('levelOneDiv'))

It's width is 0. On IE it works perfectly. Does anyone have any clue on
why it happens? Do you know any resource can help me with this very
annoying issues?
Thanks to all, chr

Nov 7 '05 #1
10 3166

ch********@lateral.net wrote:
The left attribute seems the be changed but if I
check its width, using this function I refined from one I found on the
web:

function getWidth(someObject){
var w;
if (someObject.style.width){
w=someObject.style.width;
}else if(someObject.style.pixelWidth){
w=someObject.style.pixelWidth;
}else if(someObject.offsetWidth){
w=someObject.offsetWidth;
}else if(document.defaultView &&
document.defaultView.getComputedStyle) {
w=document.defaultView.getComputedStyle(someObject ,'').getPropertyValue('width');
}
if(typeof w=="string") w=parseInt(w);
return w;
}

getWidth(document.getElementById('levelOneDiv'))

It's width is 0. On IE it works perfectly. Does anyone have any clue on
why it happens? Do you know any resource can help me with this very
annoying issues.


Others will no doubt have better suggestions, but as a starting point,
have you tested which of the getWidth "if" conditions is being
triggered in Mozilla compared with IE. Also, your getWidth function is
perhaps too comprehensive, in that it is getting different values for
different conditions.

For instance the "someObject.style.width" property will only return a
value if the inline style "width" has been set on an element. I.e.
<div style="width:100px"></div>. It may be that Mozilla is returning
"0" here, if you have not set the inline style of the relevant DIV.

offsetWidth is probably your best [non standard] method of getting
actual calculated width, including borders, so I would try reducing
your get width function to just that.

Julian

Nov 7 '05 #2

ch********@lateral.net wrote:
The left attribute seems the be changed but if I
check its width, using this function I refined from one I found on the
web:

function getWidth(someObject){
var w;
if (someObject.style.width){
w=someObject.style.width;
}else if(someObject.style.pixelWidth){
w=someObject.style.pixelWidth;
}else if(someObject.offsetWidth){
w=someObject.offsetWidth;
}else if(document.defaultView &&
document.defaultView.getComputedStyle) {
w=document.defaultView.getComputedStyle(someObject ,'').getPropertyValue('width');
}
if(typeof w=="string") w=parseInt(w);
return w;
}

getWidth(document.getElementById('levelOneDiv'))

It's width is 0. On IE it works perfectly. Does anyone have any clue on
why it happens? Do you know any resource can help me with this very
annoying issues.


Others will no doubt have better suggestions, but as a starting point,
have you tested which of the getWidth "if" conditions is being
triggered in Mozilla compared with IE. Also, your getWidth function is
perhaps too comprehensive, in that it is getting different values for
different conditions.

For instance the "someObject.style.width" property will only return a
value if the inline style "width" has been set on an element. I.e.
<div style="width:100px"></div>. It may be that Mozilla is returning
"0" here, if you have not set the inline style of the relevant DIV.

offsetWidth is probably your best [non standard] method of getting
actual calculated width, including borders, so I would try reducing
your get width function to just that.

Julian

Nov 7 '05 #3
Hi Julian, Firefox calls the offsetWidth. But the problem that worries
me more is that if you look this simple example:

http://nuthinking.com/test/lateral/div_move.html

In firefox the bg color of the div disappears after moving it and also
its width crashes :(
Thanks, chr

Nov 8 '05 #4
I found finally a way, it is assigning in this case the width
properties before moving, so something like:

var divW=getWidth(document.getElementById('levelOneDiv '));
getStyleObject("levelOneDiv").width=divW+"px";
getStyleObject("levelOneDiv").left = (w+10)+"px";
I hope it can help someone, chr

Nov 9 '05 #5

gabon wrote:
I found finally a way, it is assigning in this case the width
properties before moving, so something like:

var divW=getWidth(document.getElementById('levelOneDiv '));
getStyleObject("levelOneDiv").width=divW+"px";
getStyleObject("levelOneDiv").left = (w+10)+"px";
I hope it can help someone, chr


Hi. Good suggestion. You may have found some kind of bug there worth
reporting (or perhaps already on) the bugzilla database for Mozilla.
I.e. perhaps the DIV element is losing its layout some where along the
line.

Julian

Nov 9 '05 #6
gabon wrote:
Hi Julian, Firefox calls the offsetWidth. But the problem that worries
me more is that if you look this simple example:

http://nuthinking.com/test/lateral/div_move.html

In firefox the bg color of the div disappears after moving it and also
its width crashes :(


Your example is not even Valid XHTML. Let alone that you serve XHTML
as text/html, relying on the tagsoup parser's error-correction (while
disregarding SGML NET) instead of the XML parser. And `innerHTML' is
not supposed to work for XHTML.
PointedEars
Nov 9 '05 #7
Julian Turner wrote:
[...] You may have found some kind of bug there worth reporting
(or perhaps already on) the bugzilla database for Mozilla.


Probably not.
PointedEars
Nov 9 '05 #8

Thomas 'PointedEars' Lahn wrote:
Julian Turner wrote:
[...] You may have found some kind of bug there worth reporting
(or perhaps already on) the bugzilla database for Mozilla.


Probably not.
PointedEars


You very likely to be right. Tried a number of search combinations,
but couldn't find one.

Julian

Nov 9 '05 #9
Julian Turner wrote:
Thomas 'PointedEars' Lahn wrote:
Julian Turner wrote:
> [...] You may have found some kind of bug there worth reporting
> (or perhaps already on) the bugzilla database for Mozilla.


Probably not.
[...]


You very likely to be right. Tried a number of search combinations,
but couldn't find one.


What I mean is that it is unlikely that this is a browser bug, see
<14****************@PointedEars.de>. (So you can indeed read my
statement as negating the entire OR condition, meaning that neither
of its parts is probable ;-))
PointedEars

P.S.
Please learn how to quote properly:
<http://www.jibbering.com/faq/faq_notes/pots1.html#ps1Trim>
Nov 9 '05 #10

Thomas 'PointedEars' Lahn wrote:
[snip]
What I mean is that it is unlikely that this is a browser bug, see
<14****************@PointedEars.de>. (So you can indeed read my
statement as negating the entire OR condition, meaning that neither
of its parts is probable ;-))
I understand.

[snip] Please learn how to quote properly:
<http://www.jibbering.com/faq/faq_notes/pots1.html#ps1Trim>


I am still seeking to improve. I assume you are commenting on my
inclusion of your signature.

Regards

Julian

Nov 9 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin Russ | last post by:
Hi, Although this is in VB.NET, I don't believe it's language specific. I have an application that has several panes (similar to Visual Studio in the Solution Explorer - Solution, Search,...
1
by: Bob Bedford | last post by:
Hello, I've coded a tab pages somes years ago, with a search engine (with the help of an other programmer) allowing to search in many divs (any tab show/hide a div). Now, I've to change code...
1
by: Kent Feiler | last post by:
Seemed like a good day to bring this up. I've been shooting for the impossible dream, a screen that looks exactly the same on FF and IE. I know that the big difference between FF and IE regards...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
3
by: useenu | last post by:
Hi all, I am new to this forum and javascript. I am developing a progress bar in javascript. For that I planned to have series of small DIVs in a big DIV. I have written a below function.It is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.