Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Basics of Drag & Drop | Introduction to Modern Web APIs
Quizzes & Challenges
Quizzes
Challenges
/
JavaScript Web APIs Essentials

bookBasics of Drag & Drop

When you want users to move items around on a page, the Drag & Drop API provides an easy way to make elements draggable and define where they can be dropped. The process revolves around two main roles: draggable elements (what you pick up and move) and drop targets (where you can drop those items). The API uses several key events that help you control what happens at each stage of the drag-and-drop process.

The most important events are:

  • dragstart: fires when you begin dragging a draggable element;
  • dragover: fires repeatedly as you move the dragged item over a valid drop target;
  • drop: fires when you release the dragged item over a drop target.

By setting up handlers for these events, you can control what is allowed to be dragged, where it can be dropped, and what happens when the drop occurs. This makes it possible to build interactive interfaces like file uploads, sortable lists, or custom editors.

index.html

index.html

style.css

style.css

script.js

script.js

copy
question mark

Which event is triggered when a draggable element is dropped onto a valid drop target?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 3

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookBasics of Drag & Drop

Deslize para mostrar o menu

When you want users to move items around on a page, the Drag & Drop API provides an easy way to make elements draggable and define where they can be dropped. The process revolves around two main roles: draggable elements (what you pick up and move) and drop targets (where you can drop those items). The API uses several key events that help you control what happens at each stage of the drag-and-drop process.

The most important events are:

  • dragstart: fires when you begin dragging a draggable element;
  • dragover: fires repeatedly as you move the dragged item over a valid drop target;
  • drop: fires when you release the dragged item over a drop target.

By setting up handlers for these events, you can control what is allowed to be dragged, where it can be dropped, and what happens when the drop occurs. This makes it possible to build interactive interfaces like file uploads, sortable lists, or custom editors.

index.html

index.html

style.css

style.css

script.js

script.js

copy
question mark

Which event is triggered when a draggable element is dropped onto a valid drop target?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 3
some-alt