onseeking

The onseeking event in HTML is triggered when a media element starts seeking to a new playback position, allowing scripts to respond to this action.

onseeking event

The onseeking event in HTML occurs when a user starts a seek operation on a media element, like <audio> or <video>. This gives developers the ability to run actions or scripts while the media is in the process of seeking to a new position.

Syntax

In HTML

index.html
<element onseeking ="myScript">

In JS

script.js
object.onseeking  = function(){myScript};

In JavaScript, the addEventListener() function is used.

script.js
object.addEventListener("seeking ", myScript);

Example

::event-onseeking ::
index.html
<!DOCTYPE html> 
<html> 
<body> 
<h1>HTML DOM Events</h1>
<h2>The onseeking Event</h2>

<p>Assign an "onseeking" event to a video element:</p>

<video controls onseeking="myFunction()">
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<p>Video courtesy of <a href="https://institute.qarpeo.com" target="_blank">Tree</a>.</p>

<p>Try to move to a new position in the video.</p>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML +=  "Seek operation began! ";
}
</script>

</body> 
</html>

Values

Conclusion

The onseeking event allows developers to respond when a user starts seeking to a new position in a media element. It provides a way to track or trigger actions during the seek process. This helps enhance interactivity and control over media playback.