accessing <area> attributes in Mozilla?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabe Moothart

    #1

    accessing <area> attributes in Mozilla?

    I would like to be able to dynamically change the attributes of an <area>
    element in an image map. The following works in IE 6 and Opera 7:

    <map name="Map1">
    <area shape="rect" coords="10,10,1 00,50" href="foo.html" id="area1">
    </map>
    ....
    <script>
    document.area1. href = "bar.html";
    </script>

    but it doesn't work in Mozilla 1.4. I tried using name="area1", but that
    didn't work either. Is there any way to referrence the attributes of an
    <area> tag in Mozilla?

    thanks,
    Gabe
  • Martin Honnen

    #2
    Re: accessing &lt;area&gt; attributes in Mozilla?



    Gabe Moothart wrote:
    [color=blue]
    > I would like to be able to dynamically change the attributes of an <area>
    > element in an image map. The following works in IE 6 and Opera 7:
    >
    > <map name="Map1">
    > <area shape="rect" coords="10,10,1 00,50" href="foo.html" id="area1">
    > </map>
    > ...
    > <script>
    > document.area1. href = "bar.html";
    > </script>
    >
    > but it doesn't work in Mozilla 1.4. I tried using name="area1", but that
    > didn't work either. Is there any way to referrence the attributes of an
    > <area> tag in Mozilla?[/color]

    You need to learn how to access an element with an id attribute set with
    script:
    var area;
    if (document.getEl ementById) {
    area = document.getEle mentById('area1 ');
    if (area) {
    area.href = 'bar.html';
    }
    }
    That works with IE5+, Netscape 6+, Mozilla, Opera 7 and any other
    browser implementing the W3C DOM Core and HTML

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Lee

      #3
      Re: accessing &lt;area&gt; attributes in Mozilla?

      Gabe Moothart said:[color=blue]
      >
      >I would like to be able to dynamically change the attributes of an <area>
      >element in an image map. The following works in IE 6 and Opera 7:
      >
      ><map name="Map1">
      > <area shape="rect" coords="10,10,1 00,50" href="foo.html" id="area1">
      ></map>
      >...
      ><script>
      >document.area1 .href = "bar.html";
      ></script>
      >
      >but it doesn't work in Mozilla 1.4. I tried using name="area1", but that
      >didn't work either. Is there any way to referrence the attributes of an
      ><area> tag in Mozilla?[/color]

      The correct way to referrence it in any modern browser:
      document.getEle mentById('area1 ').href

      Comment

      Working...