Search code examples
javascripthtmldictionarygoogle-visualizationarea

Get HTML area tag name from Javascript?


I would like to display area tag name after a person clicks on it. Unfortunately when I use code below for map area I get undefined name of obiekt name. It's weird because for textbox 'kot' it works well.

<script>

function metoda(obiekt)
{
    alert(obiekt.name); //Here I get undefined!
}

</script>

<input type='text' value='kot' name='das' onclick='metoda(this);'></input>
<map name='mapkama'>
   <area 
      name='AE' 
      shape='POLY' 
      coords='285,87,287,90,288,87,285,87' 
      href='#'  
      title='' 
      onclick='metoda(this); return false;'>
</map>

<img usemap="#mapkama" src='http://myimage.com/image'>

How to display area name from metoda function?


Solution

  • using jquery you can achieve this by

    <script type="text/javascript"> 
    
    function metoda(obiekt) 
    { 
        alert(obiekt.getAttribute("name")); 
    } 
    
    </script> 
    
    <input type='text' value='kot' name='das' onclick='metoda(this);'></input> 
    
    <img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap" />
    
    <map name="planetmap">
      <area name='AE1' shape="rect" coords="0,0,82,126" href="#" alt="Sun" onclick='metoda(this); return false;'/>
    </map>