HTML | ondragenter Event Attribute

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
Before dragging the content:

After dragging the content:



Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.