Categories
JavaScript Answers

How to get the current YouTube video time with JavaScript?

Spread the love

Sometimes, we want to get the current YouTube video time with JavaScript.

In this article, we’ll look at how to get the current YouTube video time with JavaScript.

How to get the current YouTube video time with JavaScript?

To get the current YouTube video time with JavaScript, we use the getCurrentTime method.

For instance, we write

const ytPlayer = document.getElementById("movie_player");
const time = ytplayer.getCurrentTime();

to select the YouTube player element with getElementById.

Then we call getCurrentTime to get the current time of the video.

Conclusion

To get the current YouTube video time with JavaScript, we use the getCurrentTime method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *