agon024 agon024 - 11 days ago 4x
jQuery Question

jQuery - remove video auto play on click

I am using:

$("#vid1")[0].src += "&autoplay=1";

to automatically start a video when a button is clicked and its sets the source as:

How can I remove the autoplay=1 and set it to autoplay=0 when I click a second button.



Give this a try

var newSource = $("#vid1").attr('src').replace("&autoplay=1", "&autoplay=0");
$("#vid1").attr('src', newSource );

A few things to note:


The [0] isn't needed. You're selecting an ID and it should only appear once. If you were selecting a class that could appear more than once you'd use .eq(0)

This will only work if you've already appended the &autoplay=1 to the src. If this is a problem add a check to see if it's there or not.