A RetroSearch Logo

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

Search Query:

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

HTML ondragenter Event Attribute - GeeksforGeeks

HTML ondragenter Event Attribute

Last Updated : 11 Jul, 2025

The ondragenter Event attribute in HTML works when the content is draggable. An element is made by setting the draggable attribute value to true. The draggable attribute can take only true or false values and activates when a dragged element enters a valid drop target.

Syntax
<element ondragenter = "script">
Attribute Value

This attribute contains a single value script which works when ondragenter event attribute is called. 

Example 1: In this example, we will see the implementation of the above event tag with an example.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML ondragenter Event Attribute
    </title>
  
    <!-- script to add background color -->
    <script>
        function MyFunction() {
            document.getElementById("geeks").
                style.backgroundColor = "green";
        } 
    </script>
</head>

<body id="geeks" style="text-align:center">
  
    <!-- ondragenter event call here -->
    <h1 ondragenter="MyFunction()" draggable="true">
        GeeksforGeeks
    </h1>
    <p>
        Drag heading content to
        change background color
    </p>
</body>

</html>

Output:

Example 2: In this example, we will see the implementation of the above event tag with an example.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML ondragenter Event Attribute
    </title>
    <script>
        function dragenter_time() {
            document.getElementById("geeks").
                innerHTML = "The date and time is: " + Date();
        } 
    </script>
</head>

<body>
    <center>
      
        <!-- ondragenter event call here -->
        <p style="font-size: 30px;" 
           id="geeks" ondragenter="dragenter_time()" 
           draggable="true">
          Drag to know time
        </p>
    </center>
</body>

</html>

Output:

Supported Browsers

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