Click to See Complete Forum and Search --> : Changing <area>


kapot
03-25-2003, 05:16 AM
Hi,

I need to be able to change href inside <area> by clicking a link.

Here is my code :

function clearit() {
document.mymap.innerHTML = "<area shape='rect' coords='170,11,242,61' nohref>";
}

<map name="mymap">
<area shape="rect" coords="14,244,66,298" href="#" onClick="slideit(3)" alt="" >
</map>


<a href="#" onClick="clearit()">set_NOHREF</a>

So, if I click the set_NOHREF link, the "mymap" area will be UNCLICKABLE by setting "nohref". But my code gave me error. Anyone know how to implement this?

Thanks.

Phil Karras
03-25-2003, 09:07 AM
Yes, you almost had it, try something like this:

function clearit() {
var obj = document.getElementById('mymap');
obj.innerHTML = "<area shape='rect' coords='170,11,242,61' nohref>";
}

Or, as you can see you can now use this function to do the same thing to any ID area by passing the name of the ID to the function, to do so use:

function clearit(MyID) {
var obj = document.getElementById(MyID);
obj.innerHTML = "<area shape='rect' coords='170,11,242,61' nohref>";
}

One last thing, you now need to change:
<map name="mymap">
to
<map id="mymap">

This is the correct form for using innerHTML and getElementById both of which are DOM level 1 methods. (This means they work only in browsers: NS6.0 & up and IE5.0 & up.)