onplaying
The onplaying event in HTML is triggered when media playback resumes after being paused, allowing developers to perform actions or updates in response.
onplaying event
The onplaying
event attribute in HTML is triggered when media playback resumes after a pause. It enables developers to run actions or scripts in response to the media starting to play again.
Syntax
In HTML
index.html
<element onplaying ="myScript">
In JS
script.js
object.onplaying = function(){myScript};
addEventListener()
function is used. In JavaScript, the
script.js
object.addEventListener("playing ", myScript);
Example
::event-onplaying
::
index.html
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onplaying Event</h2>
<p>Assign an "onplaying" event to a video element.</p>
<video controls onplaying="myFunction()">
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<p>Play, pause and then play the video again.</p>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML += "The video is playing. ";
}
</script>
</body>
</html>
Values
Conclusion
The onplaying
event in HTML helps trigger actions when media playback resumes. It enables developers to improve the user experience by executing scripts when the media starts playing again. This event is especially valuable for interactive media applications.