0

I am trying to access the play button of a vimeo video in my page. Since it's an iframe, I am not able to get the play button using jquery.

Here is the code that tried:

$(".component.video.detail").on("click", ".vp-controls > button", function () {
    alert("triggered play button");
});

also this didn't work:

$(document).on("click", ".vp-controls > button", alert("triggered play button"));

Any help or insights will be greatly appreciated.

manaslu
  • 143
  • 7
  • Possible duplicate of [Can javascript access iframe elements from the parent page?](https://stackoverflow.com/questions/729577/can-javascript-access-iframe-elements-from-the-parent-page) – MattSizzle Nov 24 '19 at 22:33
  • That post answers only to Can I, I need help with how can I? – manaslu Nov 24 '19 at 22:44

1 Answers1

0

Typically, you have to access the document of the iFrame and then search for the element in there.

const iFrame = document.getElementById('iFrameID');
const innerDocument = iFrame.contentDocument || iFrame.contentWindow.document;

As per MattSizzle's link, this only works within the same domain. Since this is an external Vimeo video, you will not be able to access its internals since cross-site scripting is a security violation.