Editing HTML 5
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 313: | Line 313: | ||
<pre>function drag(ev) { | <pre>function drag(ev) { | ||
ev.dataTransfer.setData("text", ev.target.id); | ev.dataTransfer.setData("text", ev.target.id); | ||
− | } | + | }</pre> |
− | </pre> | ||
In our example, the data type is "text" and the value is the ID of the draggable element ("image"). | In our example, the data type is "text" and the value is the ID of the draggable element ("image"). | ||
Line 328: | Line 327: | ||
In the example above, the ondrop attribute calls a function, '''drop(event)''': | In the example above, the ondrop attribute calls a function, '''drop(event)''': | ||
− | < | + | <dev>function drop(ev) { |
ev.preventDefault(); | ev.preventDefault(); | ||
var data = ev.dataTransfer.getData("text"); | var data = ev.dataTransfer.getData("text"); | ||
ev.target.appendChild(document.getElementById(data)); | ev.target.appendChild(document.getElementById(data)); | ||
− | } | + | }</dev> |
− | </ | ||
The '''preventDefault()''' method prevents the browser's default handling of the data (default is open as a link on the drop). | The '''preventDefault()''' method prevents the browser's default handling of the data (default is open as a link on the drop). |
Advertising: