A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-ondrag-event-attribute/ below:

HTML ondrag Event Attribute - GeeksforGeeks

HTML ondrag Event Attribute

Last Updated : 11 Jul, 2025

The ondrag event attribute triggers when the element or text selection is being dragged in HTML. This event is very similar to the drag-and-drop event. This will triggered during a drag operation when an HTML element is being dragged.

Syntax
<element ondrag = "script">
Supported Tags

It supports all HTML Elements

Attribute Value

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

Example: This example illustrates the implementation of the HTML ondrag Event Attribute.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>ondrag event attribute</title>
    <style>
        body {
            text-align: center;
        }

        #geeks {
            border: 1px solid black;
            padding: 15px;
            width: 60%;
        }
    </style>
</head>

<body>
    <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>
</body>

</html>

Output:

Supported Browsers

The browser supported by ondrag event attribute are listed below: 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4