Search code examples
jqueryimagemap

drag drop element on image map get value


I have a image map and want to drag and drop one element i.e. pin on Country Map. When the pin drops on map. I need that image map ID.

<p id="draggable" style="position: absolute; bottom: 10px; left: 40px; cursor: move; z-index:100;"><img src="images/pin1.png"/></p>
<img src="image.gif" width="145" height="126" alt="Elements" usemap="#elementmap" />
    <map name="elementmap">
    <area id="element1"  class="droppable" shape="rect" coords="0,0,82,126" alt="Element 1"/>
    <area id="element2" class="droppable" shape="circle" coords="90,58,3" alt="Element 2"/>
</map>

jQuery code is like this:

$("#draggable").draggable();
$(".droppable").droppable({
    accept: '#draggable',
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    drop: function (event, ui) {
        var targetElem = $(this).attr("id");

        var draggableId = ui.draggable.attr("id");
        var droppableId = $(this).attr("id");

        alert(targetElem);
        alert(draggableId);
        alert(droppableId);

    }
});

Here is the jsFiddle example: http://jsfiddle.net/fguru/ZKQ2x/2/

Is there any way around.


Solution

  • http://www.w3schools.com/html/html5_draganddrop.asp

    Try adding draggable="true" property to your img tag