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 onemptied Attribute
Photo Credit to CodeToFun
🙋 Introduction
The onemptied
attribute in HTML is an event handler attribute that is triggered when a media element, such as <audio> or <video>, is reset to its initial state.
This event occurs when the media resource becomes empty or when the user seeks back to the beginning of the media.
🎯 Purpose of onemptied
The primary purpose of the onemptied
attribute is to allow developers to execute JavaScript code or functions when the emptied event occurs.
This can be useful for handling specific actions or behavior adjustments in response to the media element being reset.
💎 Values
The onemptied
attribute accepts JavaScript code or function references.
When the media element is emptied, the associated JavaScript code or function is executed.
Here's an example of how to use the onemptied
attribute:
<video controls onemptied="handleEmptyEvent()">
<source src="example.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<script>
function handleEmptyEvent() {
console.log("Media element has been emptied!");
// Add your custom logic here
}
</script>
🧠 How it Works
In this example, the onemptied
attribute is set to call the handleEmptyEvent function when the associated <video> element is emptied
🔄 Dynamic Values with JavaScript
Just like with other event handler attributes, you can also dynamically assign values to the onemptied
attribute using JavaScript.
This enables you to customize the behavior based on dynamic conditions or user interactions. Here's a brief example:
<script>
// Dynamically set the onemptied attribute for a video element
document.getElementById("dynamicVideo").onemptied = function() {
console.log("Dynamic onemptied event triggered!");
// Add your dynamic logic here
};
</script>
🧠 How it Works
In this script, the onemptied
attribute is dynamically set for a video element with the id dynamicVideo.
🏆 Best Practices
- Use the
onemptied
attribute to handle specific actions or adjustments when a media element is emptied. - Consider providing alternative content or user feedback when media elements are emptied, especially if the media is a crucial part of your web page.
- Ensure cross-browser compatibility by testing the behavior of the
onemptied
attribute in various browsers.
🎉 Conclusion
The onemptied
attribute is a valuable tool for enhancing the interactivity of web pages that include media elements.
By utilizing this attribute and understanding its behavior, you can create more dynamic and responsive user experiences.
👨💻 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 onemptied Attribute), please comment here. I will help you immediately.