oh the only copy and pasted code is $('#video1')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*'); which is a command to tell a youtube iFrame to stop playing the video. Also generally I mix vanilla JS and jQuery a lot since I read that vanilla JS is faster, but when it comes to finding a certain element in a div I use jQuery.