Skip to content
Related Articles

Related Articles

Improve Article
HTML | ondragenter Event Attribute
  • Difficulty Level : Basic
  • Last Updated : 04 Jan, 2019

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

Syntax:

<element ondragenter = "script">

Attribute Value: This attribute contains single value script which works when ondragenter event attribute called.

Example 1:




<!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:
Before dragging the content:

After dragging the content:



Example 2:




<!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 id = "geeks" ondragenter="dragenter_time()"
                draggable = "true">Drag to know time
            </p>
        </center>
    </body>
</html>                    

Output:
Before dragging the content:

After dragging the content:

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

  • google Chrome 4.0
  • Internet Explorer 9.0
  • Firefox 3.5
  • Safari 6.0
  • Opera 12.0



My Personal Notes arrow_drop_up
Recommended Articles
Page :