HTML Basic
HTML Reference
- HTML Tags
- HTML Deprecated Tags
- HTML Events
- HTML Attributes
- accept
- accept-charset
- accesskey
- action
- align
- alt
- as
- async
- autocomplete
- autofocus
- autoplay
- bgcolor
- border
- charset
- checked
- cite
- class
- color
- cols
- colspan
- content
- contenteditable
- controls
- coords
- data
- data-*
- datetime
- default
- defer
- dir
- dirname
- disabled
- download
- draggable
- enctype
- enterkeyhint
- for
- form
- formaction
- headers
- height
- hidden
- high
- href
- hreflang
- http-equiv
- id
- inert
- inputmode
- ismap
- kind
- label
- lang
- list
- loop
- low
- max
- maxlength
- media
- method
- min
- multiple
- muted
- name
- novalidate
- onabort
- onafterprint
- onbeforeprint
- onbeforeunload
- onblur
- oncanplay
- oncanplaythrough
- onchange
- onclick
- oncontextmenu
- oncopy
- oncuechange
- oncut
- ondblclick
- ondrag
- ondragend
- ondragenter
- ondragleave
- ondragover
- ondragstart
- ondrop
- ondurationchange
- onemptied
- onended
- onerror
- onfocus
- onhashchange
- oninput
- oninvalid
- onkeydown
- onkeypress
- onkeyup
- onload
- onloadeddata
- onloadedmetadata
- onloadstart
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onmousewheel
- onoffline
- ononline
- onpagehide
- onpageshow
- onpaste
- onpause
- onplay
- onplaying
- onpopstate
- onprogress
- onratechange
- onreset
- onresize
- onscroll
- onsearch
- onseeked
- onseeking
- onselect
- onstalled
- onstorage
- onsubmit
- onsuspend
- ontimeupdate
- ontoggle
- onunload
- onvolumechange
- onwaiting
- onwheel
- open
- optimum
- pattern
- placeholder
- popover
- popovertarget
- popovertargetaction
- poster
- preload
- readonly
- rel
- required
- reversed
- rows
- rowspan
- sandbox
- scope
- selected
- shape
- size
- sizes
- span
- spellcheck
- src
- srcdoc
- srclang
- srcset
- start
- step
- style
- tabindex
- target
- title
- translate
- type
- usemap
- value
- width
- wrap
- HTML Global Attributes
- HTML Status Code
- HTML Language Code
- HTML Country Code
- HTML Charset
- MIME Types
HTML ondragend Attribute
Photo Credit to CodeToFun
🙋 Introduction
The ondragend
attribute is a valuable feature in HTML that enables developers to define a JavaScript function to be executed when the user has finished dragging an element.
This attribute is commonly used in conjunction with the HTML Drag and Drop API to provide enhanced interactivity and responsiveness to drag-and-drop operations on a web page.
🎯 Purpose of ondragend
The primary purpose of the ondragend
attribute is to specify a JavaScript function that will be invoked when the user completes the dragging of an element.
This event occurs after the user releases the mouse button or lifts their finger (in the case of touch devices) to conclude the drag operation.
💎 Values
The ondragend
attribute accepts a JavaScript function as its value. This function will be called when the drag operation is completed. Here's a simple example:
<div draggable="true" ondragend="handleDragEnd(event)">
<!-- Content to be dragged -->
</div>
<script>
function handleDragEnd(event) {
// Your custom logic for handling the drag end event
console.log("Drag operation completed!");
}
</script>
🧠 How it Works
In this example, the ondragend
attribute is set to the handleDragEnd function, which will be executed when the drag operation is finished.
🔄 Dynamic Values with JavaScript
You can dynamically set the ondragend
attribute using JavaScript, allowing you to adjust the behavior based on different conditions or user interactions. Here's an example:
<script>
// Dynamically set ondragend for an element
document.getElementById("dynamicDragElement").ondragend = function(event) {
// Your dynamic logic for handling the drag end event
console.log("Dynamic drag operation completed!");
};
</script>
🧠 How it Works
In this script, the ondragend
attribute is dynamically set for an element with the id dynamicDragElement. This provides flexibility in defining the drag end behavior based on your application's requirements.
🏆 Best Practices
- Use the
ondragend
attribute to define clear and responsive behaviors after a drag operation is completed. - Ensure that the associated JavaScript function handles the drag end event appropriately, considering the specific requirements of your application.
- Test the drag-and-drop functionality across different browsers to ensure consistent behavior.
🎉 Conclusion
The ondragend
attribute is a valuable tool for adding interactivity to drag-and-drop operations in HTML.
By leveraging this attribute along with the Drag and Drop API, you can create dynamic and engaging user experiences on your web page.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (HTML ondragend Attribute), please comment here. I will help you immediately.