7

I want to change the cursor when dragging, so I try this way:

function drag (event) {

    localStorage.setItem("no", $(event.target).data("no"));

    $("html").css("cursor", "move");

}
<tr draggable="true" class="memo_item move" id="memo_<?php echo $memo->memo_no?>" ondragstart="drag(event, this);" data-no="<?php echo $memo->memo_no?>"></tr>

but it doesn't work.

And I can't use JQueryUi.

How can I change cursor?

ElChiniNet
  • 2,778
  • 2
  • 19
  • 27
조서환
  • 73
  • 1
  • 3

1 Answers1

0

Simply implement this kind of event setup in your code...

$('<some element here>').on('dragstart', function() {
  $(this).css("cursor", "move");
});

However, this will permanently change the cursor on the element, to toggle this cursor change add

$('<some element here>').on('dragend', function() {
  $(this).css("cursor", "default"); // or whatever pointer you want to revert to
});
Rafael
  • 7,605
  • 13
  • 31
  • 46
  • 1
    Above code just use jQuery to register H5 drag event. No jQuery UI. @NathanHornby By thy way, it seems we cannot just drag cursor. – Ricky Jiao Apr 01 '16 at 15:51
  • My mistake. Their presence in the jQuery UI docs, but not in the jQuery docs led me to believe otherwise - hadn't realised they were native events as part of the DragEvent interface https://developer.mozilla.org/en-US/docs/Web/API/DragEvent – Nathan Hornby Oct 24 '16 at 09:48
  • 5
    This does not change the cursor. I am not aware of a way to do this since HTML5 drag locks the pointer to `default`. – Sergio May 03 '17 at 20:34
  • I am not sure of the intent here. But you don't need js to change a cursor on hover. There is nothing locking the cursor to `default`. https://jsfiddle.net/8nh6ekbp/ – Rafael May 04 '17 at 15:38
  • fiddle by Rafael ( jsfiddle.net/8nh6ekbp ) doesn't work. cursor is indeed locked – Nir O. Nov 14 '19 at 10:54