Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Map: Click to echo/print text on screen

Is it possible to click a portion of an image map and print out some text, be it the alt or title value of that <area> tag somewhere on the page?

Could I do this through jQuery? I've looked and I'm struggling to do so (very rusty with jQuery, and a novice on top of it). I've played with a bit of code but all I manage to get is static data out.

Thanks.

Edit: This is one large image with 30 uniquely sized and shaped "areas" that are clickable.

like image 412
scrot Avatar asked Sep 10 '09 20:09

scrot


1 Answers

HTML:

<map name="Map" id="Map">
  <area shape="rect" coords="32,36,222,109" href="#" alt="hi" />
  <area shape="rect" coords="246,45,420,110" href="#" alt="alt" />
  <area shape="rect" coords="456,45,585,111" href="#" />
  <area shape="rect" coords="627,44,768,118" href="#" />
</map>

jQuery:

<script type="text/javascript">
 $(function(){
  $('map area').click(function(){
   alert($(this).attr('alt'));
  });
 });
</script>
like image 59
Colin Avatar answered Nov 06 '22 02:11

Colin