dynamically created elements are not accessible with document.getElementsByName

VERIFIED INVALID

Status

()

VERIFIED INVALID
17 years ago
10 years ago

People

(Reporter: martin.honnen, Assigned: jst)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

17 years ago
The following (which will be attached as a test case) first document.writes a
couple of span elements with the same name attribute (a2ndSpan), then creates a
couple of span elements with document.createElement and sets the .name attribute
property of those elements all to the same value (aSpan).
While the document.written spans are found by document.getElementsByName, the
dynamically created spans are not.
<html>
<head>
<title>
document.getElementsByName
</title>
<style>
span { border: 1px solid green; }
</style>
</head>
<body onload="alert(document.getElementsByName('a2ndSpan').length);
alert(document.getElementsByName('aSpan').length);">
<script>
var n = Math.floor(Math.random() * 10) + 1;
var html = '';
for (var i = 0; i < n; i++)
  html += '<span name="a2ndSpan">a2ndSpan ' + i + '. <\/span>';
document.write(html);
</script>
<br \/>
<script type="text/javascript">
for (var i = 0; i < n; i++) {
   var span = document.createElement('span');
   span.name = 'aSpan';
   span.appendChild(document.createTextNode('aSpan ' + i + '. '));
   document.body.appendChild(span);
}
</script>
</body>
</html>
(Reporter)

Comment 1

17 years ago
Created attachment 45062 [details]
test case (shows that spans are not found)
Possibly related:

Look at http://www.w3.org/TR/2000/WD-DOM-Level-2-HTML-20001113/html.html

It says that SPAN only implements the HTMLElement interface. This interface does
not include a name property....

OS: Windows 95 → All
Hardware: PC → All
(Assignee)

Comment 3

17 years ago
Replace:

 span.name = 'aSpan';

with:

 span.setAttribute('name', 'aSpan');

and this should work, INVALID.
Status: NEW → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → INVALID

Comment 4

17 years ago
replacing span.name with span.setAttribute('name', 'foo') worked..marking as
verified...
Status: RESOLVED → VERIFIED

Updated

10 years ago
Component: DOM: HTML → DOM: Core & HTML
QA Contact: stummala → general
You need to log in before you can comment on or make changes to this bug.