anchors not added to document.anchors unless have name= attribute set




14 years ago
14 years ago


(Reporter: peakle, Assigned: bugzilla)


Firefox Tracking Flags

(Not tracked)





14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0

A page has a set of anchor tags (<a>). javascript code accesses document.anchors
and expects to find all the anchor tags there, but not all the tags are found in
that array.  Appers that only the anchors with a name="somevalue" tag attribute
are present.  Those which only specify id="somevalue" (no 'name' tag attribute)
don't appear.  In IE6 they do not require name="value" to appear, but that is
not the case in Mozilla 1.7.1 or Firefox 1.0.  A small HTML file that duplicates
this is included below in section Additional Information.

Reproducible: Always

Steps to Reproduce:
1. Run the enclosed html page under debugger.
2. Set breakpoint in javascript function removeLineNos().
3. Click the button Remove Line Numbers
4. Step till value of document.anchors is accessed.  Then open that array and
look at the content.  Will only have 4 items, rather than 6 (<a> tags "l3" and
"l4" will not be there).

Actual Results:  
document.anchors only contains 4 items (rather than 6)

Expected Results:  
all 6 <a> tags should be in document.anchors

** HTML file that duplicates this problem **

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">
    <title>Mozilla Bug</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <meta name="keywords" content="view, rate example, java, source file"/>
    <script type="text/javascript">
var savedAnchorValues;

function removeLineNos() {
   if (savedAnchorValues != null && savedAnchorValues.length > 0) {
   var anchors = document.anchors;
   var inputElt;
   savedAnchorValues = new Array(anchors.length);
   for (i = 0; i < anchors.length; i++) {
       if ((anchors[i].className == "ln") || (anchors[i].className == "ln_hit")) {
           savedAnchorValues[i] = anchors[i];
           anchors[i].removeChild(anchors[i].firstChild); // remove TextNode

function restoreLineNos() {
   if (!(savedAnchorValues && savedAnchorValues.length > 0)) {
   var txt;
   var anchors = document.anchors;
   for (i = 0; i < anchors.length; i++) {
      if ((anchors[i].className == "ln") || (anchors[i].className == "ln_hit")) {
           txt = document.createTextNode(savedAnchorValues[i]);
   savedAnchorValues = null;
    <style type="text/css">
    .ln  { color: #808080; background-color: #eef5fe;}

&lt;a&gt; tag must have attribute name="value" or won't be present in
           <input type="button" value="Remove Line Numbers"
onClick="removeLineNos()" />
           <input type="button" value="Restore Line Numbers"
onClick="restoreLineNos()" />

           <a class="ln" name="l1">L1</a>
           <a class="ln" name="l2">L2</a>
           <a href="#" class="ln" id="l101" name="l101">L101</a>
           <a href="#" class="ln" id="l102" name="l102">L102</a>

	   <!-- following won't be returned by javascript: document.anchors: -->
           <a class="ln" id="l3">L3</a>
           <a class="ln" id="l4">L4</a>


The DOM standard makes it quite clear that anchors without a name attribute must
not be included in the anchors collection. You'd think Microsoft would know
that, since they link to the DOM1 page which says the same thing from their
documentation page where they say that they include both name and id.
Last Resolved: 14 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.