DIVs and SPANs can't be addressed by ID.

VERIFIED WONTFIX

Status

()

Core
DOM: Core & HTML
P3
major
VERIFIED WONTFIX
18 years ago
18 years ago

People

(Reporter: stilltim, Assigned: jst)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

18 years ago
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
BuildID:    20000721

Attempting to change the properties of a specific DIV or SPAN (using javascript 
to address the element by an assigned ID) produces a "<DIV ID> has no 
properties" error. See the HTML below for an example. Also, the problem does 
not seem to be limited just to DIVs and SPANs.  I have also seen this problem 
for table cells with IDs assigned. All of these cases work in Internet Explorer 
4+

Reproducible: Always
Steps to Reproduce:
1. Create a DIV or SPAN an assign it an ID.
2. Try to use javascript to access any property of the DIV or SPAN object.
3. Receive error					

This is a really important capability of most dynamic HTML I've seen.  As a web 
developer, I really need this to work.

(The javascript in this example should change the displayed text from "It's not 
working" to "It works."  Instead, the browser produces a "testspan is not 
defined" error.  Adding "document." at the beginning of 
the "testspan.innerHTML=" line changes the error to "testspan has no 
properties"). 

<HTML>
<HEAD>
<TITLE>Test Case</TITLE>

<SCRIPT LANGUAGE="javascript">
   function testcontent()
      {testspan.innerHTML="<P>It works</P>"}
</SCRIPT> 

</HEAD>

<BODY onLoad="testcontent()">

<SPAN ID="testspan">
  <P>It's Not Working</P>
</SPAN>

</BODY>
</HTML>
(Assignee)

Comment 1

18 years ago
Mozilla intentionally does not reflect elemets with an id as properties on the
document even if some other browsers do so to some extent. The correct DOM way
of accessing elements by their ID is to use the DOM Document method
getElementById(), if you use getElementById() your code will be (closer to) DOM
Level 1&2 compliant.

In your sample, in stead of using:

  testspan.innerHTML="<P>It works</P>"

you should be using:

  document.getElementById('testspan').innerHTML="<P>It works</P>"

Marking this bug as WONTFIX.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 18 years ago
OS: Windows 2000 → All
Hardware: PC → All
Resolution: --- → WONTFIX

Comment 2

18 years ago
Verifying.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.