LuckyCoder
LuckyCoder

Reputation: 520

jQuery click() for video element

I'm working on SimpleWebRTC. When new party join a room, new video element is added. Now I need to handle click on any of the video element. So I write the code bellow

$('video').click(function(e) {
       console.log('clicked');

       e.preventDefault()
});

Obviously the block was within jQuery document ready. But I'm not seeing anything on console. The weird thing is when I'm pasting the code above in console of browser, that's working as expected.

I need your guideline to solve the issue.

Thanks.

Upvotes: 1

Views: 3902

Answers (2)

Marek Woźniak
Marek Woźniak

Reputation: 1776

First of all: define a class for video tag. For example: .chat like this:

<video class="chat" />

and use this code:

$('video.chat').on('click', function (e) {
    console.log(this);
});

or:

$(document).on('click', 'video.chat', function (e) {
    console.log(this);
});

I hope it helps you.

Upvotes: 1

Luis Gar
Luis Gar

Reputation: 471

Try to give an id to the video element so your script should be

$('#video').click(function(e) {
       console.log('clicked');

       e.preventDefault()
});

So it should show the text "clicked" on console but I'm not sure there will happen any more

Upvotes: 0

Related Questions