Ivan Kochurkin
Ivan Kochurkin

Reputation: 4501

Extract css class from drag-and-drop event in javascript

I have several draggable image elements with certaing css class and one canvas element on my html page. Also canvas element catches dragStart, dragOver and drop events. How is it possible to find out image css class in drop event? Image src I can get with following code: e.dataTransfer.getData('text').

UPDATE:

Here my javascript function (generated from C# with ScriptSharp):

_drop: function Collage$_drop(e) {
    /// <param name="e" type="ElementEvent">
    /// </param>
    e.preventDefault();
    var x = _privateUtils.getMouseX(e) - 20;
    var y = _privateUtils.getMouseY(e) - 20;
    this._loadCollageImage(x, y, e.dataTransfer.getData('text'));
}

Is it possible to get css image class or another unique element feature (attribute, id) from e or by the other way?

Upvotes: 0

Views: 482

Answers (1)

robertc
robertc

Reputation: 75777

If you want information to be available in the drop event, add it to the dataTransfer object in the drag event. Or just set the text to be the ID of the element, and fetch the required information from the DOM.

Upvotes: 1

Related Questions