jQuery HTML Element How to - Handle click event on map








Question

We would like to know how to handle click event on map.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-compat-git.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from w  w  w . j a  va 2 s  . c  o m-->
   $('area').on('click', function(){ console.log('click'); })
});
</script>
</head>
<body>
  <img src="http://www.java2s.com/style/download.png" usemap="#map" />
  <map name="map">
    <area shape="rect" coords="25,25,75,75" href='#' />
  </map>
</body>
</html>

The code above is rendered as follows: