Jump to content

Change the Video source with a button click

Recommended Posts


I'm trying to dynamically change the source of a video with a button click. I have several videos to display and would love to be able the user to change them when needed. 

I have tried it with a normal button and a code element.

I have added code:

function changeVideoSource() {
  // JavaScript code to change the video source
  // For example:
  var video = document.getElementById('block-yui_3_17_2_1_1709155643233_4986');
  video.src = 'https://youtu.be/7m94ip38UKs?si=YEmrvTrkIkR6Zqgw';
 console.log('Video source changed Successfully:', video.src); 

  alert('Video source changed successfully!'); 


 <button onclick="changeVideoSource()">Change Video Source</button>


"Video source changed. Successfully: https://youtu.be/7m94ip38UKs?si=YEmrvTrkIkR6Zqgw"


But the source doesnt change.

Can you see any thing I'm doing wrong?

Link to comment
  • Replies 2
  • Views 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment

  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.