Open In App
Related Articles

HTML ondrag Event Attribute

Improve Article
Improve
Save Article
Save
Like Article
Like

The ondrag event attribute trigger when the element or text selection is being dragged in HTML. This event is very similar to the drag-and-drop event. This attribute is new in HTML 5.

Syntax: 

<element ondrag = "script">

Attribute Value: This attribute contains a single value script that works when an element is dragged. It is supported by all HTML elements.
Example: 

Javascript




<style>
    #geeks {
        border: 1px solid black;
        padding: 15px;
        width: 60%;
    }
</style>
<center>
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2>ondrag event attribute</h2>
    <div id="geeks" draggable="true" 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>

Output: 

 

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

Supported Tags: It supports all HTML Elements. 

Last Updated : 24 Nov, 2022
Like Article
Save Article
Similar Reads
Related Tutorials