I'd like to change my cursor to 'move' when using HTML 5 browser drag and drop. However, when I move the draggable item, this cursor remains unchanged (default). According to MDN documentation and other various Stackoverflow posts with this same question, the dataTransfer object can be set to move. However, when setting this property, the cursor remains unchanged.
function dragstart_handler(ev) {
// Add the target element's id to the data transfer object
ev.dataTransfer.setData("application/my-app", ev.target.id);
ev.dataTransfer.effectAllowed = "move";
}
function dragover_handler(ev) {
ev.preventDefault();
ev.dataTransfer.dropEffect = "move";
}
function drop_handler(ev) {
ev.preventDefault();
const data = ev.dataTransfer.getData("application/my-app");
ev.target.appendChild(document.getElementById(data));
}
.drop-zone {
width: 300px;
height: 200px;
border: solid 1px red;
}
<p id="p1" draggable="true" ondragstart="dragstart_handler(event)">
This element is draggable.
</p>
<div
id="target"
class="drop-zone"
ondrop="drop_handler(event)"
ondragover="dragover_handler(event)">
Drop Zone
</div>