Which event occurs in JavaScript when an element is dragged completely?

The ondragend event triggers when an element is dragged completely.


You can try to run the following code to learn how to implement ondragend event in JavaScript.

         .drag {
            float: left;
            width: 100px;
            height: 35px;
            border: 2px dashed #876587;
            margin: 15px;
            padding: 10px;

      <div class="drag" ondrop = "drop(event)" ondragover = "dropNow(event)">
         <p ondragstart = "dragStart(event)" ondragend = "dragEnd(event)" draggable = "true" id = "dragtarget">Drag!</p>

     <div class = "drag" ondrop = "drop(event)" ondragover = "dropNow(event)"></div>
     <div id = "box"></div>
     <p>Drag the left box to the right or drag the right box to the left.</p>
        function dragStart(event) {
           event.dataTransfer.setData("Text", event.target.id);
        function dropNow(event) {
        function dragEnd(event) {
           document.getElementById("box").innerHTML = "Dragging ends!";
        function drop(event) {
           var data = event.dataTransfer.getData("Text");
           document.getElementById("box").innerHTML = "The element dropped successfully!";