473,396 Members | 1,804 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.

ie win and getElementById()

Hi.
I've got a div I insert into a document with script , assigning it an
id with div.setAttribute() so I can grab a reference to it with
getElementById() and manipulate its classname. This works like a charm
in mozilla and safari. In ie5+, the getElementById returns null. I've
made sure the id isn't duplicated and also checked that the div
actually is successfully inserted with the correct id attribute.
Actually, I'm not sure where else to look. Any suggestions?

Sep 27 '05 #1
3 1439

cf*******@gmail.com wrote:
Hi.
I've got a div I insert into a document with script , assigning it an
id with div.setAttribute() so I can grab a reference to it with
getElementById() and manipulate its classname. This works like a charm
in mozilla and safari. In ie5+, the getElementById returns null. I've
made sure the id isn't duplicated and also checked that the div
actually is successfully inserted with the correct id attribute.
Actually, I'm not sure where else to look. Any suggestions?


Hi cfeldmann,

In IE, the setAttribute method does not work properly. A work around
for what you're trying to do is simply doing the following instead:

div.id = "myId";

Sep 27 '05 #2
Hi.
This is something I hadn't actually tried, so I did this and also
div["id"] = "id", but neither seems to change the result. In all three
cases (these two and setAttribute()), I can dump(div.nodeName +
node.getAttribute("id")) immediately afterward and see that it is
successfully created and appended to the tree. It's just gone later
when I try to get it with a different chunk of seperately loaded script.

Sep 27 '05 #3
cf*******@gmail.com a écrit :
Hi.
This is something I hadn't actually tried, so I did this and also
div["id"] = "id", but neither seems to change the result.

var objDiv = document.createElement("div");
objDiv.id = "asdf";

should work in all browsers, even MSIE 5.x.
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-63534901

In all three cases (these two and setAttribute()), I can dump(div.nodeName +
node.getAttribute("id")) immediately afterward and see that it is
successfully created and appended to the tree.

You also need to check the name attribute because MSIE mixes names and
id attribute values in the collection list (that's a spec violation by
MSIE 5+ actually). If there is another element with the same attribute
value, then MSIE will render the first encountered.

E.g.: <input name="asdf" ...> will interfere with return value of
document.getElementById("asdf") depending on the place of the call and
the respective places of other elements.

e.g.:

<input name="asdf" ...>
(...)
<div id="asdf" ...>

and here if you query document.getElementById("asdf"), then the input
element will be fetched, not the div.
It's just gone later when I try to get it with a different chunk of seperately loaded script.


Your problem may depend on how your whole page DOM tree is built and/or
how you've coded all this. You have not provided an url for the webpage
so that we could examine the issue. So it's not possible to know for
sure what is the problem..

Gérard
--
remove blah to email me
Sep 28 '05 #4

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

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
7
by: PaulB | last post by:
Good Morning everybody, I'm trying to adapt a tutorial script that will handle the behaviour of an "Expanding/Contracting" site-navigation menu. The code that seems to handle the expansion and...
3
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...
1
by: Andre Ranieri | last post by:
Hello, I'm trying to set up an ASP.NET 2.0 form where the user enters values in WebControls.TextBoxes for amount owing, interest and late fees and a JavaScript function totals the three values...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
13
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...
5
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
1
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...
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:
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: 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
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
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.