$(document).ready(function (e) {
var img = $('img');
var clickunit = 20;
var mapcode = '<map name="Map" id="Map">';
img.attr('usemap','#Map');
// get the width and height of the image then divide it by click unit
var w = img.width();
var h = img.height();
// start loop - height first - like a typewriter
var tw = 0;
var th = 0;
for(y=0;y<h;y+=clickunit){
for(x=0;x<w;x+=clickunit){
mapcode += '<area shape="rect" coords="' + x + ',' + y + ',' + parseInt(x+clickunit) + ',' + parseInt(y+clickunit) + '" href="javascript:void(0);" onclick="alert(\'X: ' + x + ' Y: ' + y + '\');" />';
}
}
mapcode += '</map>';
$('body').append(mapcode);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.