2

I have an image map that has a few dozen elements, most of which are fixed. But some are conditional, and I want them to be active some but not all of the time.

Is there a way to disable/enable an <area> element without removing it from the DOM?

Jason S
  • 184,598
  • 164
  • 608
  • 970

3 Answers3

0

Unfortunately there is no 'disable' attribute, but I've found that if you give the hotspot no surface area, then the user cannot click it and it appears to be hidden.

For a circle...

document.getElementById('mapname').areas[areaindex].coords="0,0,0";

or, for a rectangle...

document.getElementById('mapname').areas[areaindex].coords="0,0,0,0";
GeoReb
  • 21
  • 1
  • 10
0

You can try to add/remove attribute disabled to the area element.

Stelian Matei
  • 11,553
  • 2
  • 25
  • 29
  • The `area` element doesn't have a "disabled" attribute. (http://www.w3.org/TR/html401/struct/objects.html#h-13.6.1) You must be thinking of textareas. – Jason S Feb 10 '12 at 19:31
  • You are right, sorry. I should have read more carefully the question. – Stelian Matei Feb 10 '12 at 19:34
0

If you handle the onclick event with a return false; you can prevent it from linking to it's href when clicked.

document.getElementById("your-area-id").setAttribute("onclick", "return false;");

This kills the link.

I notice you don't have the question tagged with JavaScript so...

<area href="some-url.html" onclick="return false;" />

... will work just as well.

Are there any other behaviors you need disabled or just this?

Matthew
  • 8,183
  • 10
  • 37
  • 65