How Do I Dynamically Add &autoplay=1 To Youtube Embed Codes? May 31, 2023 Post a Comment This is an examples of the youtube embed code on my site: ).val(function(i, oldVal) { return oldVal + (oldVal.indexOf('?') ? '&autoplay=1' : '?autoplay=1'); }); $('embed').prop('src', function(i, oldSrc) { return oldSrc + (oldSrc.indexOf('?') ? '&autoplay=1' : '?autoplay=1'); } CopyYou might prefer to do a slightly more specific selector, for instance $('embed[src^="http://www.youtube.com/"]') or perhaps $('object param[name="movie"]') -- it depends on what your page contains elsewhere...See the API reference:attribute-equals selectorvalpropSolution 2: To play a YouTube movie by JavaScript, you'll better use the JavaScript Player API:http://code.google.com/intl/nl/apis/youtube/js_api_reference.html (Yes I know this is not precisely the answer to the OP's question).Baca JugaFinding Open Graph Tags On YoutubeHide Div After Youtube Video EndsYoutube Api - Onplayerstatechange Share You may like these postsHow To Make Youtube Embedded Video Load Only When Box AppearsReplace Url From Youtube To Embed Code - Error: Permission Denied To Access Property 'tostring'Controlling Playback Of Multiple Youtube Videos With The Youtube Js Api (playing At The Same Time)Turn Multiple Youtube/vimeo Links Into Embedded Players Post a Comment for "How Do I Dynamically Add &autoplay=1 To Youtube Embed Codes?"