Skip to content
Related Articles

Related Articles

HTML | ondrag Event Attribute

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 18 Aug, 2022
View Discussion
Improve Article
Save Article

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.
Supported Tags: It supports all HTML elements. 


<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.


<!DOCTYPE html>
    <title>ondrag event attribute</title>
        #geeks {
            border: 1px solid black;
            padding: 15px;
            width: 60%;
        h1 {
            color: green;
        <h2>ondrag event attribute</h2>
        <div id="geeks" ondrag="Function()">
            GeeksforGeeks: A computer science portal for geeks
            function Function() {
                document.getElementById("geeks").style.fontSize = "30px";
                document.getElementById("geeks").style.color = "green";

Before Drag the content: 

After Drag the content: 

Supported Browsers: The browser supported by ondrag event attribute are listed below: 

  • Chrome 3.0
  • Edge 12.0
  • Internet Explorer 9.0
  • Firefox 3.5
  • Safari 3.1
  • Opera 12.0

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!