Back to Content

DataTransfer: addElement() method

files/en-us/web/api/datatransfer/addelement/index.md

latest1.1 KB
Original Source

{{APIRef("HTML Drag and Drop API")}}{{SeeCompatTable}}{{Non-standard_header}}

The DataTransfer.addElement() method sets the drag source to the given element. This element will be the element to which {{domxref("HTMLElement/drag_event", "drag")}} and {{domxref("HTMLElement/dragend_event", "dragend")}} events are fired, and not the default target (the node that was dragged).

[!NOTE] This method is Firefox-specific.

Syntax

js-nolint
addElement(element)

Parameters

  • element
    • : The {{domxref("Element")}} to set as the drag source.

Return value

None ({{jsxref("undefined")}}).

Examples

This example shows the use of the addElement() method

js
function changeDragNode(event, node) {
  const dt = event.dataTransfer;
  dt.addElement(node);
}

Specifications

This method is not defined in any Web standard.

Browser compatibility

{{Compat}}

See also