View Full Version : javascript variables and element ID in IE6
I've noticed that Internet Explorer doesn't like javascript variable names which are the same as an elements ID or 'name'. Have people bumped into this issue (or is it just me :-) )?
I've pulled out numerous hairs chasing down bugs related to this issue. Once I changed the variable name and reverted back to the original code things worked fine.
Just wondering if anyone else has seen this (miserable, now bald, people love company).
Wayne Christian
wac@genesyslab.com
IE exposes document.all on top of the window object as well.
document.all.bla == document.all('bla') == document.all['bla'] == window.bla == bla;
Really bad decision on their part, among others.
brothercake
10-22-2002, 01:51 AM
It's not the best no; it's also dangerous in the sense that iterating through the all collection is very inefficient; yet the ease with which objects are exposed gives you false impression that it's something you might want to use.
But are you talking about things like
var something = document.getElementById("something") ?
Which presumably you want to do to make it easier to remember what things are? In which case I have two suggestions. The first is to take advantage of javascript's case sensitivity and use that to differentiate in a way that shouldn't be problematic. eg
var someThing = document.getElementById("something")
The second suggestion - comment a lot. Preferably every line.
beetle
10-22-2002, 04:04 PM
Ditto on what brothercake said. For object IDs I try to use underscores, and uppercasing for 2-word variable names
<div id="some_thing"></div>
var someThing = document.getElementById('some_thing');
However, whenever possible, I try to encapsulate my code in functions that use generic variable names...like o, i, node, arr, stuff like that....
RadarBob
10-26-2002, 09:08 PM
http://www.webreference.com/js/
The above link has some decent tutorials on the DOM - and more to the point a couple of "columns" on the differences between IE and NN.
good luck!
P.S. if/when you figure it all out let me know!
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.