473,396 Members | 1,998 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,396 software developers and data experts.

Problem finding properties using JS

Hi!

I am not that experienced with javascript and I am having a problem reading some properties using javascript.

I have a menu bar sitting inside a div that is centred. Some menu options drop down from the bar, with their left position being set in css.

I want to read the left position using JS becaues the position of the dropdown boxes will change depending on the width of the browser plus every time I change a menu I hqve to recode the values that turn the menus on and off.

I found the code below, but in Firefox it returns 0px (seems to be wrong) while IE returns 160px (correct, but does not allow for the centering - just reporting the left within its div).
Expand|Select|Wrap|Line Numbers
  1. var x = document.getElementById(el);
  2. if (x.currentStyle)
  3. {
  4.      var y = x.currentStyle[styleProp];
  5. }else if (window.getComputedStyle){
  6.      var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
  7. }
  8.     return y;
  9.  
If I inspect the offsetLeft property I just get auto from both browsers. Is there any way of reading either the elements absolute position on the page, or getting its correct left property in firefox and its offset from the left of the page in both browsers?

Thanks in advance,

Dave
Aug 5 '07 #1
2 1117
pbmods
5,821 Expert 4TB
Heya, Dave. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

Have a look at this article.
Aug 5 '07 #2
Thank you so much pbmods, sorry about the ettiquette breach...

I can now get everything working fine in IE, but firefox is still flummoxing me. This code

Expand|Select|Wrap|Line Numbers
  1. x = document.getElementById('pageLinksBox1').offsetParent;
  2. y = x.id;
  3. alert(getStyle(y, 'left'));
  4.  
is fine for IE, but in Firefox, while x is an object that contains the box (verified by setting the .top property and seeing the element move), firefox returns 'null' for the .offsetParent. This is set correctly in IE, so I assume that I am making some mistake with the code....

The code

Expand|Select|Wrap|Line Numbers
  1. x = document.getElementById('pageLinksBox1');
  2. alert (x.id);
  3.  
  4. y = x.offsetParent;
  5. alert (y.id);
  6.  
produces an alert with the correct name (pageLinksBox1) in firefox and then breaks the javascript processing with an error that says that y has no properties...

Sorry to be obtuse, but does anyoneknow what I am doing wrong?

Thanks in advance

Dave
Aug 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: waltborders | last post by:
Hi, Because the blind are unable to use a mouse, keyboard navigation is key. A major difficulty is that not all windows forms controls are keyboard 'tab-able' or 'arrow-able' or have "tab...
0
by: Curtis Hatter | last post by:
I apologize if this has been answered, but on the .NET 247 site I saw a thread titled "Datagrid's ItemCommand Event", and had similar troubles with the Datagrid not properly firing the delete event...
3
by: Phil Kelly | last post by:
Hi! I hope someone can help me here because I'm tearing my hair out (what little there is of it!) trying to figure out what's going on with the code below. I'm passing an Active Directory CN...
1
by: | last post by:
Hello, I'm keping myself busy here by investigating the world of LDAP and Active Directory. I have an application which allows users from the system to be selected from a list box and as a...
9
by: Dave Booker | last post by:
When I run a particular application I've been working on for a while, it somehow finds a value for the Application Setting "Test.Properties.Settings.Default.ProjectPath", but I can't see where it...
1
by: Kev | last post by:
Gidday, I am stuck trying to create a COM Callable Wrapper for the class (shell only) below. As you can see I have tried to define my interface and it would be all good if I wasn't passing my...
17
by: NetworkElf | last post by:
Hi all, I'm writing a service that needs to discover the full directory path for a given locally based share at startup. IOW, I need to have the service running on someserver to take ...
2
by: dougmcmurtry | last post by:
I have an Asynchronous socket that sends data to a server for credit card approvals. The socket is kept alive by the server through a heartbeat that sends a "beat" every 90 seconds. Trouble is that...
3
by: TEST | last post by:
I am saving images out from a camera to bmp using directshow. I can open these images in mspaint or any other image program without a problem. Using: HBITMAP h_Bitmap; h_Bitmap =...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.