Reputation: 168
I am working with video.js
and video.js
library is loading via script tag I want to track click function on list item and update player-menu.
$(".vjs-menu-item").on("click" ,function(){ alert('selector');});
but not working this one
$(document).on("click",".vjs-menu-item", function() {alert('document'); });
Hence $(document)
method only works on these items which added on same page i.e
<p id="vjs-menu-item"> click me </p>
Upvotes: 0
Views: 4019
Reputation:
$(document).ready(function(){
$("#vjs-menu-item").click(function(){
alert('document');
});
});
Upvotes: 0
Reputation: 50291
Here the selector is id
but you are referencing to a class
Change to this
$(document).on("click","#vjs-menu-item", function() {alert('documnet'); });
or use class
instead of id in html
HTML
<p class="vjs-menu-item">Click me</p>
JS
$(document).on("click",".vjs-menu-item", function() {
alert('document');
});
Upvotes: 4