Solved

jQuery: Which element was moved?

Posted on 2014-03-11
2
338 Views
Last Modified: 2014-03-11
In this example, items may be dragged however I do not know how the dragged item can be identified.  I want the id of the dragged element to be returned in an alert.
http://jsfiddle.net/f4fZP/1/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="http://draggabilly.desandro.com/draggabilly.pkgd.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
var items = document.querySelectorAll('.pins>div');
  for ( var i=0, len = items.length; i < len; i++ ) {
    var item = items[i];
    var draggie = new Draggabilly( item );
    draggie.on( 'dragEnd', onDragEnd );
  }
function onDragEnd( draggie ) {
  alert( 'ID of pin that was moved: ????');
  alert( 'X: ' + $(this)[0]['position']['x'] +'\nY: '+ $(this)[0]['position']['y']);
}
});
</script>
<style type="text/css">
html, body, .pins {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.pins>div {
position: absolute;
width: 20px;
height: 20px;
background: red;
}
</style>
</head>
<body>
 <div class="pins">
  <div id="pin1" style="left: 40px; top: 50px;"></div>
  <div id="pin2" style="left: 120px; top: 140px;"></div>
  <div id="pin3" style="left: 200px; top: 130px;"></div>
 </div></body>
</html> 

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39920393
Try this:
alert( 'ID of pin that was moved: ' + draggie.element.id);

Open in new window

0
 
LVL 56

Expert Comment

by:Julian Hansen
ID: 39920408
You can try
draggie.element.id

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question