473,789 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getElementbyId problem in Firefox

TR
My document had the following nested DIV structure, with a possible
<SPAN> between the DIV and the <A> elements:

<div id="container" >
<div id="D1">
<span>blah blah</span><br>
<A id="A1">item</a><br>
Jul 23 '05 #1
4 6819
DU
TR wrote:
My document had the following nested DIV structure, with a possible
<SPAN> between the DIV and the <A> elements:

<div id="container" >
<div id="D1">
<span>blah blah</span><br>
<A id="A1">item</a><br>
.
.
.
<A id="A99" onmousedown='AO CP(1,99)'>item</a><br>
<div id="D2">
<A id="A76" onmousedown='AO CP(1,65)'>item</a><br>
.
.
.
<A id="A89" onmousedown='AO CP(1,34)'>item</a><br>
</div>
</div>

I see 3 div start tag and 2 div end tag.
When the user puts the mouse down on any ANCHOR, my script needs to
determine the anchor's parent DIV. The following script worked at first

85 function getParentDiv(el ementid) {
86 /* elementid is the id of the <A> where the user is clicking;
the <a> may be nested inside a <SPAN> so loop until first DIV is
encountered; */
87
88 var activeElement = document.getEle mentById(elemen tid);
89 do
90 {
91 if (activeElement. tagName != 'DIV')
92 activeElement = activeElement.p arentElement;
93 }
94 while ( (activeElement. tagName != 'DIV') || (activeElement. tagName
=='HTML') )
95
96 if ((activeElement != null) && (activeElement. tagName == 'DIV') )
97 return activeElement.i d;
98 else
99 return -1;
100
101
102 } /* end function */
But the script stopped working with this error "Line 94 activeElement
has no properties" (taken from the Firefox javascript console) when I
merely added a second container DIV ("outercontaine r"):
<div id="outercontai ner">
<div id="container" >
<div id="D1">
<span>blah blah</span><br>
<A id="A1">item</a><br>
.
.
.
<A id="A99" onmousedown='AO CP(1,99)'>item</a><br>
<div id="D2">
<A id="A76" onmousedown='AO CP(1,65)'>item</a><br>
.
.
.
<A id="A89" onmousedown='AO CP(1,34)'>item</a><br>
</div>
</div>
</div>

4 start tag, 3 end tag.
I don't understand why this error is occuring when my former structure
has merely been enclosed within a DIV. Could someone please explain?
After a certain depth of nesting, does getElementById stop working in
Firefox? The script continues to work fine in IE6 and Opera 7.

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040206
Firefox/0.8
Thanks
TR


1- Is your document perfectly valid? No improper nesting error reported
by the W3C HTML validator?
http://validator.w3.org/

2- Can you post an url? It is not only more convenient, making your post
smaller but it will show the http headers which is sometimes decisive
when trying to solve a problem

DU
Jul 23 '05 #2
TR wrote:
<snip>
88 var activeElement = document.getEle mentById(elemen tid);
89 do
90 {
91 if (activeElement. tagName != 'DIV')
92 activeElement = activeElement.p arentElement; ^^^^^^^^^^^^^
parentElement - is a Microsoft proprietary property that has been
implemented in some other browsers but not in Mozilla/Gecko browsers.
The W3C Core DOM property with the most similar characteristics is -
parentNode -.

<snip I don't understand why this error is occuring when my former structure
has merely been enclosed within a DIV. Could someone please explain?
After a certain depth of nesting, does getElementById stop working in
Firefox? The script continues to work fine in IE6 and Opera 7.


As parentElement was always undefined in Firefox it is unlikely that
this code ever did what you thought it was doing in that browser.

Richard.
Jul 23 '05 #3
Thank you for the information. I was using devguru.com as my
online reference and would be grateful if you could suggest
another site that is comparable in approach but which identifies
the proprietary things. Do you know of a good one?
TR
P.S. Opera appears to support activeElement if Firefox does not.

Jul 23 '05 #4
Thanks for the reply. The missing closing tags were a feature of
my question, not of the HTML in the actual page. The HTML there is
valid. We're still working on the site and don't have it loaded
onto a webserver at the moment, or I'd be happy to provide a URL.
It looks as though the problem arose from my inadvertent use of a
Microsoft proprietary property.
TR
In article <c8**********@n ews.eusc.inter. net>,
dr*******@hotWI PETHISmail.com replies...

1- Is your document perfectly valid? No improper nesting error reported
by the W3C HTML validator?
http://validator.w3.org/

2- Can you post an url? It is not only more convenient, making your post
smaller but it will show the http headers which is sometimes decisive
when trying to solve a problem

DU

Jul 23 '05 #5

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

Similar topics

10
1909
by: Dave Hammond | last post by:
Hi All, The following code works in IE but not Firefox. IE produces the expected "this is more text!" output, but Firefox produces "no more text". Any ideas why? <BODY> <FORM> <INPUT TYPE=HIDDEN NAME="moreText" VALUE="<PRE>This is more text!</PRE>">
1
3427
by: Muffinman | last post by:
Howdy, I've got here a sample of my function which is supposed to fade a certain piece of text to another colour. This line is then located in a for loop and it works pretty well in IE 6. However, in Firefox, and thus I assume it will be the same in Netscape and Mozilla, it gives a problem with the: getElementById('main_txt'). Due to that in setTimeout("",) it requires the "" signes and thus I can not use the same ones in the getElement...
5
31226
by: Derek Erb | last post by:
I am banging my head against the wall with this one. The following code snippets work perfectly fine in MSIE6. But produce an error in Firefox and do not work at all. BROWSER.HTM <HTML> .... <div class="Abb"> <h2 id="ABTit">BROWSER</h2> </div>
3
9276
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to work on FireFox or Netscape. What could be wrong? The function: function setActiveTab(tabNo) {
5
4341
by: Andrea | last post by:
I am trying to alter css using javascript as well as use the innerHTML function. I have pasted below 3 forms that access getElementById in slightly different ways (I wanted to rule out that it was the method.) All 3 work fine on IE but only work momentarily on Firefox. For example, one form has text that changes from red to black when the user clicks the button. In IE it changes. In Firefox it changes for a split second then goes back...
4
2667
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6 but is a dead fish in FireFox. There is no support offered on the site where it came from. I'd really appreciate help with this as it will not only to get it working but to learn how it all works so I can add it to my repertoire. Thanks!
13
4966
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the internet. When I run Firebug on it, it says: document.getElementById("TICKER") has no properties TICKER_CONTENT = document.getElementById("TICKER").innerHTML; Here is the complete script:
8
3144
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox" post. Third, there are pieces of this code that I am not at liberty to display, change, discuss, or re-implement. As far as this question is concerned, this means that (1) I cannot use 3rd party libraries, which is why I've implemented my own...
3
2064
by: GarryJones | last post by:
The following works in MSIE but not firefox. I suspect it has something to do with the fact that the element I am trying to access is not the "tid" which is the name of the DIV that is passed to this javascript. The function is a "show/hide" for a form. I want to ensure that any possible previously entered value is cleared so the user starts with an empty field with focus. I have tried to ways, with naming and getElementById but in...
1
2240
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the script to update the display to the user depending on what they choose (qty, options, shipping etc.) I'm sure it's simple but I could really use a hand. Thanks!!
0
9499
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2898
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.