Create a variable

I have this nifty little effect on my page to drag elements


when I select/drag an element, I get

Not really sure why it prints twice (It happened when I moved my mouse)
But whatever.
That looks like the newx and ycoordinates of the moved object, heres the fubction

        function endDrag(evt) {
          selectedElement = false;
		  console.log(offset.x);
		  console.log(offset.y);
        }

How can I also output the id of the object dragged
Here the HTML of the object I dragged

<g id="72" class="jqeasytooltip draggable-group" data-tiptheme="tipthemewhite"  data-tipcontent="Ramp">
    <rect x="148" y="105" width="140" height="90"  class="element"/>
    <text x="153" y="125" >Ramp</text>
</g>

Is there a way to output 72 in the log, so I can get 3 things

  1. the id of the dragged object
  2. the new x position
  3. the new y position

thanks

Hi @lurtnowski, well there’s a bit of context missing as offset is not defined in that function either, but generally you might get the ID via the event.target:

function endDrag (event) {
  selectedElement = false

  console.log(
    event.offsetX, 
    event.offsetY, 
    event.target.id
  )
}
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.