Tuxedo
10/29/2014 8:51:00 PM
Tuxedo wrote:
> Tuxedo wrote:
> [...]
>
> If only the image with its id initially exists, as follows:
>
> <img src="mymap.jpg" id="hello">
>
> ... after the page and image loaded, how can in a function the elements
> and nodes be dynamically added, for example, to createElement: MAP(#mymap)
> for the existing IMG(hello) image object and appendChild AREA with
> href(bla), coords(100,100,300,300) and shape(rect) attributes?
>
Are there some errors or inconsistencies in the following map creation
procedure of the existing IMG element?:
var map = document.createElement("map");
map.setAttribute("name","mymap");
var area = document.createElement("area");
area.setAttribute("href","bla");
area.setAttribute("coords","100,100,300,300");
area.setAttribute("shape","rect");
document.getElementById("hello").setAttribute("usemap","#mymap");
document.body.appendChild(map);
map.appendChild(area);
One difference I notice is that MAP->AREA appears at the end of the BODY
node instead of at the beginning and before the IMG element, as in the
static HTML version, below, when in the DOM Inspector's tree view.
The dynamically assigned code works without errors in the Error Console
however, although perhaps some things could be done better?..
Many thanks for any advise.
Tuxedo
> .. as if the following would have existed in static HTML to begin with:
>
> <map name="mymap">
> <area shape="rect" coords="100,100,300,300" href="bla">
> </map>
> <img src="mymap.jpg" id="hello" usemap="#mymap">
>
> Many thanks for any tips.
>
> Tuxedo