Closed
Bug 190473
Opened 23 years ago
Closed 23 years ago
javascript code to show a <div> when mouseover produces div not found error
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: tron, Assigned: jst)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020826
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020826
I have the problem described above on a page I am writing.
it works fine in IEexplorer 5.0
(please dont make me write something like "best viewed in..."
against my beliefs :) )
I was writing the following code:
...
// in javascript section
var last='empty';
function changeDiv(id)
{
// alert(id);
eval("div_"+last+".style.display='none'; div_"+id+".style.display=''");
last=id;
}
...
//in the html
<DIV ID=div_empty STYLE="position=absolute;right=0;bottom=0" >
<P ALIGN=center>empty</p>
</DIV>
....
Reproducible: Always
Steps to Reproduce:
1.load page I wrote
2.move mouse over an area
3.
Actual Results:
javascript error in console:
Error: div_empty is not defined
Source File:
file:///D:/Documents%20and%20Settings/trons/My%20Documents/%E0%E1%E9%FA%F8/web/main_browse.html
Line: 42
Expected Results:
make the <div> div_empty unvisable, and display under div
in it's place
Comment 1•23 years ago
|
||
Javascript console tell you truth: you try to eval
div_empty.style.display
But what is div_empty? Variable of unspecified type? If you want to point a link
to div with such name, you should use
document.getElementById("div_empty.style.display").
(and you don't need eval here):
document.getElementById("div_"+id+".style.display")='none';
document.getElementById("div_"+id+".style.display")='';
Comment 2•23 years ago
|
||
Ruslan is right; but reassigning to DOM Level 0 before resolving.
This is not a JS Engine issue.
IE puts all HTML ids into the global JavaScript namespace.
A W3C-compliant browser like Mozilla does not.
So if the web author has defined an element in HTML like this:
<DIV ID=div_empty STYLE="position=absolute;right=0;bottom=0" >
Then IE automatically creates a global JavaScript variable |div_empty|.
In Mozilla or any other W3C-compliant browser, you'd have to do this
yourself, in script:
var div_empty = document.getElementById('div_empty');
Note of course you do not have to use |div_empty| as the variable name.
You can choose what you want. In IE, however, this is forced on you.
Often the place to do things like this is inside an init() function
which runs off the <body> onload handler -
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale
Comment 3•23 years ago
|
||
Have to resolve as invalid; sorry -
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•