HTML | ondrag Event Attribute
The ondrag event attribute works when the element or text selection is being dragged in HTML. This event is very similar to drag and drop event. This attribute is new in HTML 5.
Syntax:
<element ondrag = "script">
Attribute Value: This attribute contains a single value script which works when an element is dragged. It is supported by all HTML elements.
Example:
<!DOCTYPE html> <html> <head> <title>ondrag event attribute</title> <style> #geeks { border: 1px solid black; padding:15px; width:60%; } h1 { color:green; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2>ondrag event attribute</h2> <div id = "geeks" ondrag="Function()"> GeeksforGeeks: A computer science portal for geeks</div> <script> function Function() { document.getElementById("geeks").style.fontSize = "30px"; document.getElementById("geeks").style.color = "green"; } </script> </center> </body> </html> |
Output:
Before Drag the content:

After Drag the content:

Supported Browsers: The browser supported by ondrag event attribute are listed below:
- Chrome 4.0
- Internet Explorer 9.0
- Firefox 3.5
- Safari: 6.0
- Opera 12.0
Recommended Posts:
- HTML | onmouseup Event Attribute
- HTML | onwheel Event Attribute
- HTML | ondragleave Event Attribute
- HTML | onmousemove Event Attribute
- HTML | onchange Event Attribute
- HTML | oninput Event Attribute
- HTML | ondblclick Event Attribute
- HTML | onload Event Attribute
- HTML | oncontextmenu Event Attribute
- HTML | onselect Event Attribute
- HTML | onsubmit Event Attribute
- HTML | onfocus Event Attribute
- HTML | onoffline Event Attribute
- HTML | onsearch Event Attribute
- HTML | onmouseover Event Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



