Closed Bug 94285 Opened 23 years ago Closed 23 years ago

dynamically created elements are not accessible with document.getElementsByName

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: martin.honnen, Assigned: jst)

Details

Attachments

(1 file)

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>
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
Replace: span.name = 'aSpan'; with: span.setAttribute('name', 'aSpan'); and this should work, INVALID.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
replacing span.name with span.setAttribute('name', 'foo') worked..marking as verified...
Status: RESOLVED → VERIFIED
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.

Attachment

General

Creator:
Created:
Updated:
Size: