JQuery click event not firing

I am using jwplayer latest version 6.8. I am trying to use the jQuery function to call when the user clicked on my logo in the player, but it does not work.

This is the HTML player logo tag:

<img class="jwlogo" id="container_logo" src="..." />

This is the jQuery function:

<script type="text/javascript">
  $(document).ready(function(){            
    $("#container_logo").click(function() { 
      alert('Work!');
    });               
  });                  
</script>

This is a test page: http://vt-test.co.nf

Any help please?

+4
source share
3 answers

Since you are using jQuery 1.3, try using jQuery.liveas follows:

$('#container_logo').live('click', function() {
    alert('Work!');
});

Note:

As with jQuery 1.7, the .live () method is deprecated.

Edit

I found a solution using the onReady event for JWPlayer:

$(function() {            
    jwplayer("container").onReady(function() {
        $('#container_logo').click(function() {
            alert('Works!');
        });
    });
});

this jsfiddle jQuery jQuery.on

+3

-, jQuery jQuery noConflict.

div click .on().

HTML:

<div id="myWrapper">
    <img class="jwlogo" id="container_logo" src="..." />
</div>

JQuery

$(document).ready(function() {
    $("#myWrapper").on("click", "#container_logo", function() {
        alert("Work!");
    });
});
+3

Actually, the top right link worked for me.

However, try:

$(document).on('click', '#container_logo', function(){  
    alert("hello"); 
});  

If elements are inserted, this will do the trick.

Since you are using an older version of jQuery (1.3.1), you should use .live(), for example:

$(document).live('click', '#container_logo', function(){  
    alert("hello"); 
});  

Also note that you can bind the wrapper to the DOM element into which the code is entered:

$('#container').on('click', '#container_logo', function(){  
    alert("hello"); 
});  
+2
source

Source: https://habr.com/ru/post/1531642/


All Articles