$(selector).on(“drag”,callback) | ondrag Event in Jquery Default

This event keeps executing its anonymous function when the element is dragging. To work on drag event, there should be applied an attribute draggable="true" on the element.

Example:-

<!DOCTYPE html>
<html>
<head>
  <title>Jquery on drag event</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p draggable="true">Drag me</p>

<script>
  $(document).ready(function(){
    $("p").on("drag",function(){
      $(this).html("dragging");
    });
  });
</script>
</body>
</html>

Leave a Comment