I want to replace the part of the given URL using button click.When I click play button need change autoplay=0 to autoplay=1 and When I click close button need change autoplay=1 to autoplay=0
jQuery(document).ready(function($) {
$('.playButton').click(function() {
alert('play');
$("iframe").src = src.replace(/\&autoplay\=\d/, "&autoplay=" + 1);
});
$(".close_icon").click(function() {
alert('close');
$("iframe").src = src.replace(/\&autoplay\=\d/, "&autoplay=" + 0);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe src="https://www.youtube.com/embed/C0DPdy98e4c?width=640&autoplay=1"></iframe>
<div class="playButton">Play</div>
<div class="close_icon">Close</div>
attr()to change thesrcattribute of iframe.$('iframe').attr('src', function(i, oldSrc) { return oldSrc.replace('autoplay=0', 'autoplay=1'); });autoplay=nin the URL?