javascriptjqueryjwplayerjwplayer6

jQuery click event not trigger


I'm using jwplayer latest version 6.8. I try to use jQuery to call function when user clicked my logo in the player but it doesn't work.

This is the logo's image tag of the player in HTML:

<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 the test page: http://vt-test.co.nf

Any help please?


Solution

  • Since you're using jQuery 1.3, try using jQuery.live like this:

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

    Note:

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

    Edit

    I found a solution using the onReady event of JWPlayer:

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

    You can see it in action in this jsfiddle However, I suggest you to update your jQuery version and use jQuery.on