Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use drag and drop events in HTML5

Shulou Source: shulou.com Published: 2022-06-03 14:37:49 11月14日 Update

This article mainly introduces how to use drag-and-drop events in HTML5. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Browser support

Internet Explorer 9, Firefox, Opera 12, Chrome, and Safari 5 support drag and drop.

Note: drag and drop is not supported in Safari 5.1.2.

HTML5 drag and drop instance

# div1 {width:488px;height:70px;padding:10px;border:1px solid # aaaaaa;} function allowDrop (ev) {ev.preventDefault ();} function drag (ev) {ev.dataTransfer.setData ("Text", ev.target.id);} function drop (ev) {ev.preventDefault (); var data=ev.dataTransfer.getData ("Text"); ev.target.appendChild (document.getElementById (data));}

Please drag and drop the picture of Aseoe logo into the rectangle: P > div >

Tags: Elements data events methods examples attributes types support content functions browsers articles facets processing browsing same code value interests pictures Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info NVidia MySQL Redmi