I have this function:
function onPlayerStateChange(event) {
if (event.data == 0){
alert(event.target.parentNode);
}
});
It is called every time a "state change" occurs for the embedded iframe. It only raises an alert message when the video ends, and according to the docs, I can get the reference to the player by calling event.target
However, I want to be able to find the parent div of event.target
but I am unable to call any jquery or regular javascript on it. How will I be able to find the parent div of the player that just ended?
event.target is not a reliable way to go about this. As Dr. Molle warned, the event.target keys do change regularly...
There is a getIframe() function which you can work from more reliably, so event.target.getIframe().parentNode
will give you the parent DIV.
event.target here doesn't return a HTML-element(iframe in this case), it returns the player-object. You may access the iframe using event.target.b (and the div by using event.target.b.parentNode).
Please note: this is not a part of the docs, I was inspecting the members of event.target by using the console. It could happen that this(the access via event.target.b) will change in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With