I need to automatically click on the “Playlist Menu Button” when an embedded YouTube playlist is first loaded (in a iFrame). I understand that this needs to be done using the YouTube iFrame API and have that script working (have installed Google’s Example 1 on their API documentation which enables different border colours depending on status).
YouTube have given the button I want to click the classes “ytp-playlist-menu-button ytp-button”.
I was hoping that adding document.getElementsByClassName("ytp-playlist-menu-button").click();
to the code below would work:
tag.id = 'iframe-demo';
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player_2', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
document.getElementById('player_2').style.borderColor = '#FF6D00';
document.getElementsByClassName("ytp-playlist-menu-button").click();
}
but it doesn’t!
Can anyone let me know what it should be to have the button clicked on when the iframe loads? You can view the page where I’m trying to do this here