TypeError: null is not an object (evaluating > 'e.relatedTarget.nodeName')










0















I need to get the data-video-id attribute and my code keeps returning a null when I request it.



HTML



<script src="https://www.youtube.com/iframe_api"></script>
<script src="js/video.js"></script>

<a data-target="#myModal" data-toggle="modal" data-video-id="VDB65S6rCC0" >
<div class="btn btn-success"> Open Modal 2</div>
</a>

<a id='video-player-1' href="#my_modal" data-toggle="modal" data-video-id="VDB65S6rCC0">Open Modal 1</a>


video.js



 var tag = document.createElement('script');

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',
height: '390',
width: '640',
videoId: 'no-video-id',
events:
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange

);



// 4. The API will call this function when the video player is ready.

function onPlayerReady(event)

$('.open-popup').click(function()
event.target.playVideo();
);

$('.close-popup').click(function(e)
player.stopVideo();
);



// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event)
if(event.data === 0)
$('.close.close-popup').click();


function stopVideo()
player.stopVideo();


$(function ()
onYouTubeIframeAPIReady();
$('#my_modal').on('show.bs.modal', function(e)
var videoId = $(e.relatedTarget).data('video-id');
var x = new String(videoId);
player.loadVideoById(x);
$("iframe[src^='https://www.youtube.com']").addClass("embed-responsive-item");
alert("BOOM!");
);

$('#video-player-1').click(function(e)
var bookId = $(e.relatedTarget).data('video-id');
alert($(e.relatedTarget.nodeName));

var x = new String(bookId);
player.loadVideoById(x);

);
);


ERROR:



When clicking the to open a modal, the related target is null.




TypeError: null is not an object (evaluating
'e.relatedTarget.nodeName')




alert(e); returns




[object Object]




Also $('#my_modal').on('show.bs.modal', function(e) { does not seem to execute.










share|improve this question
























  • The jQuery docs say that relatedTarget is for when more than one element is involved, e.g. a mouseout or mouseover event where the cursor is moving from one element to another. That's not the case here. Why do you need relatedTarget? The current element will be this.

    – Rup
    Nov 14 '18 at 1:11











  • Not sure, but it worked when tested in JSFiddle jsfiddle.net/ssorabh/k7FC2/7324, but when I moved it to my actual test site, it stopped working.

    – user2012677
    Nov 14 '18 at 1:19











  • I tested, $(e.this) and it does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:22











  • Not e.this, just $(this)

    – Rup
    Nov 14 '18 at 1:22











  • @Rup $(this) does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:25















0















I need to get the data-video-id attribute and my code keeps returning a null when I request it.



HTML



<script src="https://www.youtube.com/iframe_api"></script>
<script src="js/video.js"></script>

<a data-target="#myModal" data-toggle="modal" data-video-id="VDB65S6rCC0" >
<div class="btn btn-success"> Open Modal 2</div>
</a>

<a id='video-player-1' href="#my_modal" data-toggle="modal" data-video-id="VDB65S6rCC0">Open Modal 1</a>


video.js



 var tag = document.createElement('script');

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',
height: '390',
width: '640',
videoId: 'no-video-id',
events:
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange

);



// 4. The API will call this function when the video player is ready.

function onPlayerReady(event)

$('.open-popup').click(function()
event.target.playVideo();
);

$('.close-popup').click(function(e)
player.stopVideo();
);



// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event)
if(event.data === 0)
$('.close.close-popup').click();


function stopVideo()
player.stopVideo();


$(function ()
onYouTubeIframeAPIReady();
$('#my_modal').on('show.bs.modal', function(e)
var videoId = $(e.relatedTarget).data('video-id');
var x = new String(videoId);
player.loadVideoById(x);
$("iframe[src^='https://www.youtube.com']").addClass("embed-responsive-item");
alert("BOOM!");
);

$('#video-player-1').click(function(e)
var bookId = $(e.relatedTarget).data('video-id');
alert($(e.relatedTarget.nodeName));

var x = new String(bookId);
player.loadVideoById(x);

);
);


ERROR:



When clicking the to open a modal, the related target is null.




TypeError: null is not an object (evaluating
'e.relatedTarget.nodeName')




alert(e); returns




[object Object]




Also $('#my_modal').on('show.bs.modal', function(e) { does not seem to execute.










share|improve this question
























  • The jQuery docs say that relatedTarget is for when more than one element is involved, e.g. a mouseout or mouseover event where the cursor is moving from one element to another. That's not the case here. Why do you need relatedTarget? The current element will be this.

    – Rup
    Nov 14 '18 at 1:11











  • Not sure, but it worked when tested in JSFiddle jsfiddle.net/ssorabh/k7FC2/7324, but when I moved it to my actual test site, it stopped working.

    – user2012677
    Nov 14 '18 at 1:19











  • I tested, $(e.this) and it does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:22











  • Not e.this, just $(this)

    – Rup
    Nov 14 '18 at 1:22











  • @Rup $(this) does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:25













0












0








0


1






I need to get the data-video-id attribute and my code keeps returning a null when I request it.



HTML



<script src="https://www.youtube.com/iframe_api"></script>
<script src="js/video.js"></script>

<a data-target="#myModal" data-toggle="modal" data-video-id="VDB65S6rCC0" >
<div class="btn btn-success"> Open Modal 2</div>
</a>

<a id='video-player-1' href="#my_modal" data-toggle="modal" data-video-id="VDB65S6rCC0">Open Modal 1</a>


video.js



 var tag = document.createElement('script');

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',
height: '390',
width: '640',
videoId: 'no-video-id',
events:
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange

);



// 4. The API will call this function when the video player is ready.

function onPlayerReady(event)

$('.open-popup').click(function()
event.target.playVideo();
);

$('.close-popup').click(function(e)
player.stopVideo();
);



// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event)
if(event.data === 0)
$('.close.close-popup').click();


function stopVideo()
player.stopVideo();


$(function ()
onYouTubeIframeAPIReady();
$('#my_modal').on('show.bs.modal', function(e)
var videoId = $(e.relatedTarget).data('video-id');
var x = new String(videoId);
player.loadVideoById(x);
$("iframe[src^='https://www.youtube.com']").addClass("embed-responsive-item");
alert("BOOM!");
);

$('#video-player-1').click(function(e)
var bookId = $(e.relatedTarget).data('video-id');
alert($(e.relatedTarget.nodeName));

var x = new String(bookId);
player.loadVideoById(x);

);
);


ERROR:



When clicking the to open a modal, the related target is null.




TypeError: null is not an object (evaluating
'e.relatedTarget.nodeName')




alert(e); returns




[object Object]




Also $('#my_modal').on('show.bs.modal', function(e) { does not seem to execute.










share|improve this question
















I need to get the data-video-id attribute and my code keeps returning a null when I request it.



HTML



<script src="https://www.youtube.com/iframe_api"></script>
<script src="js/video.js"></script>

<a data-target="#myModal" data-toggle="modal" data-video-id="VDB65S6rCC0" >
<div class="btn btn-success"> Open Modal 2</div>
</a>

<a id='video-player-1' href="#my_modal" data-toggle="modal" data-video-id="VDB65S6rCC0">Open Modal 1</a>


video.js



 var tag = document.createElement('script');

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',
height: '390',
width: '640',
videoId: 'no-video-id',
events:
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange

);



// 4. The API will call this function when the video player is ready.

function onPlayerReady(event)

$('.open-popup').click(function()
event.target.playVideo();
);

$('.close-popup').click(function(e)
player.stopVideo();
);



// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event)
if(event.data === 0)
$('.close.close-popup').click();


function stopVideo()
player.stopVideo();


$(function ()
onYouTubeIframeAPIReady();
$('#my_modal').on('show.bs.modal', function(e)
var videoId = $(e.relatedTarget).data('video-id');
var x = new String(videoId);
player.loadVideoById(x);
$("iframe[src^='https://www.youtube.com']").addClass("embed-responsive-item");
alert("BOOM!");
);

$('#video-player-1').click(function(e)
var bookId = $(e.relatedTarget).data('video-id');
alert($(e.relatedTarget.nodeName));

var x = new String(bookId);
player.loadVideoById(x);

);
);


ERROR:



When clicking the to open a modal, the related target is null.




TypeError: null is not an object (evaluating
'e.relatedTarget.nodeName')




alert(e); returns




[object Object]




Also $('#my_modal').on('show.bs.modal', function(e) { does not seem to execute.







jquery youtube-iframe-api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 1:14







user2012677

















asked Nov 14 '18 at 1:06









user2012677user2012677

1,43841537




1,43841537












  • The jQuery docs say that relatedTarget is for when more than one element is involved, e.g. a mouseout or mouseover event where the cursor is moving from one element to another. That's not the case here. Why do you need relatedTarget? The current element will be this.

    – Rup
    Nov 14 '18 at 1:11











  • Not sure, but it worked when tested in JSFiddle jsfiddle.net/ssorabh/k7FC2/7324, but when I moved it to my actual test site, it stopped working.

    – user2012677
    Nov 14 '18 at 1:19











  • I tested, $(e.this) and it does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:22











  • Not e.this, just $(this)

    – Rup
    Nov 14 '18 at 1:22











  • @Rup $(this) does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:25

















  • The jQuery docs say that relatedTarget is for when more than one element is involved, e.g. a mouseout or mouseover event where the cursor is moving from one element to another. That's not the case here. Why do you need relatedTarget? The current element will be this.

    – Rup
    Nov 14 '18 at 1:11











  • Not sure, but it worked when tested in JSFiddle jsfiddle.net/ssorabh/k7FC2/7324, but when I moved it to my actual test site, it stopped working.

    – user2012677
    Nov 14 '18 at 1:19











  • I tested, $(e.this) and it does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:22











  • Not e.this, just $(this)

    – Rup
    Nov 14 '18 at 1:22











  • @Rup $(this) does not seem to work either.

    – user2012677
    Nov 14 '18 at 1:25
















The jQuery docs say that relatedTarget is for when more than one element is involved, e.g. a mouseout or mouseover event where the cursor is moving from one element to another. That's not the case here. Why do you need relatedTarget? The current element will be this.

– Rup
Nov 14 '18 at 1:11





The jQuery docs say that relatedTarget is for when more than one element is involved, e.g. a mouseout or mouseover event where the cursor is moving from one element to another. That's not the case here. Why do you need relatedTarget? The current element will be this.

– Rup
Nov 14 '18 at 1:11













Not sure, but it worked when tested in JSFiddle jsfiddle.net/ssorabh/k7FC2/7324, but when I moved it to my actual test site, it stopped working.

– user2012677
Nov 14 '18 at 1:19





Not sure, but it worked when tested in JSFiddle jsfiddle.net/ssorabh/k7FC2/7324, but when I moved it to my actual test site, it stopped working.

– user2012677
Nov 14 '18 at 1:19













I tested, $(e.this) and it does not seem to work either.

– user2012677
Nov 14 '18 at 1:22





I tested, $(e.this) and it does not seem to work either.

– user2012677
Nov 14 '18 at 1:22













Not e.this, just $(this)

– Rup
Nov 14 '18 at 1:22





Not e.this, just $(this)

– Rup
Nov 14 '18 at 1:22













@Rup $(this) does not seem to work either.

– user2012677
Nov 14 '18 at 1:25





@Rup $(this) does not seem to work either.

– user2012677
Nov 14 '18 at 1:25












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291745%2ftypeerror-null-is-not-an-object-evaluating-e-relatedtarget-nodename%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291745%2ftypeerror-null-is-not-an-object-evaluating-e-relatedtarget-nodename%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo