Forum Bugs

anchor .href assignment doesn't assign

StoneCypher
Assignment to the .href member of an anchor object dynamically created in javascript does not actually assign the attribute. Calling .setAttribute('href', whatever) works as expected.

<html>

  <head>
  
    <style type="text/css">
      #ToCol a::after { content: " " leader(".") " " target-counter(attr(href), page); }
    </style>
    
    <script type="text/javascript">

      function init() {

        var liP = document.createElement('li');
        var laP = document.createElement('a');            liP.appendChild(laP);
        var tP  = document.createTextNode('Property');    laP.appendChild(tP);

        var liD = document.createElement('li');
        var laD = document.createElement('a');            liD.appendChild(laD);
        var tD  = document.createTextNode('DOM Assign');  laD.appendChild(tD);

        laP.href = '#tgt';                   // these two should be equivalent
        laD.setAttribute('href', '#tgt');    // but only this one works

        var tgt = document.getElementById('example');

        tgt.appendChild(liP);
        tgt.appendChild(liD);

      }

    </script>

  </head>

  <body onload="init();">

    <a name="tgt">Target</a>

    <ol id="example">
      <li><a href="#tgt">Hard Link</a></li>
    </ol>

  </body>

</html>

John Haugeland is http://fullof.bs/

mikeday
Nice catch, there are a number of element-specific DOM properties that are not yet supported, such as a.href and img.src. We do plan to add these.