Home >Web Front-end >CSS Tutorial >How Can I Play and Pause HTML5 Videos Using jQuery in a Tabbed Interface?
Playing and Pausing HTML5 Videos with jQuery
In this scenario, you aim to control HTML5 videos in a tabbed interface using jQuery. The objective is to play a video when its associated tab is clicked and pause it when any other tab is activated.
The jQuery Solution
To initiate the video playback, you are utilizing the following jQuery code:
$('#playMovie1').click(function() { $('#movie1').play(); });
However, the issue arises due to the usage of the 'play' function. Unlike jQuery functions, 'play' is a native DOM method. Consequently, you need to target the DOM element to execute it effectively.
The jQuery equivalent of accessing the native DOM element is 'get'. Integrating this into your code, you can achieve the desired playback behavior:
$('#videoId').get(0).play();
Explanation
The 'get' method retrieves the native DOM element from the jQuery selection. By combining this with the 'play' function, you can directly control video playback using jQuery, ensuring a seamless experience in your tabbed interface.
The above is the detailed content of How Can I Play and Pause HTML5 Videos Using jQuery in a Tabbed Interface?. For more information, please follow other related articles on the PHP Chinese website!