Add Pause/Play Button For Background Video

October 19, 2022

In this Elementor tutorial I will show you how to add a pause/play button for a background video.

Timestamps:

  • 0:00 Introduction
  • 2:16 Add JavaScript Code
  • 4:55 Elementor Button Example

Elementor GitHub Feature Request

Native JS Events in Elementor:
https://developers.elementor.com/native-js-events-in-elementor/

JavaScript Code:

				
					<script src="https://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>
<script>
 jQuery(function($){
      let video = document.querySelector('video.elementor-background-video-hosted');
            document.getElementById('bgvideo').addEventListener('click', button_action);

            function button_action() {
                if (video.paused) {
                    video.play();
                    bgvideo.innerHTML = "Pause Video";
                } else {
                    video.pause();
                    bgvideo.innerHTML = "Play Video"
                }
            };
});
</script>
<button class="button" id="bgvideo">Pause Here</button>

				
			

*Some of the links on this page are affiliate links, meaning we may receive a commission if you follow them. This allows us to continue providing free content and educational resources for you. Thank you for supporting our small business!

Share this post:

Facebook
Reddit
Twitter
Pinterest
LinkedIn
Email

More Free Resources

Join Our Community

Wicky Design YouTube

Get our latest videos by subscribing for FREE to our YouTube channel. New videos are uploaded weekly!