0

I try to execute a function when I click on a specific div ID and nothing happens, help! Example:

$( "#jwplayer-1_wrapper" ).click(function() {
  alert( "Handler Clicked" );
});

-> Full example here <-

Samuel Charpentier
  • 491
  • 1
  • 5
  • 26

4 Answers4

2

Check this

http://jsfiddle.net/2mK7Z/22/

$(document).ready(function(event)
{
    $('#jwplayer-1_wrapper').mousedown(function() {
      alert('click detetced');
    });
});
Harsha Venkatram
  • 2,782
  • 1
  • 31
  • 57
  • Using the 'mousedown' did the trick for me instead of using click – Harsha Venkatram Dec 15 '13 at 22:52
  • This works but only if i inject the code manualy after the whole page is loaded, how can I delay it to when the flash element has loaded completly? – Samuel Charpentier Dec 15 '13 at 22:58
  • did you try it with $('#jwplayer-1_wrapper').on('mousedown',function() { alert('click detetced'); }); – Harsha Venkatram Dec 15 '13 at 22:59
  • Yes but it need to be injected manualy (since im working with an injector and I dont choose when the script is loaded (probably 1st script executed)) and it needs to load before it can execute itself – Samuel Charpentier Dec 15 '13 at 23:01
  • 1
    If you use 'on' , it should fire no matter when it is injected. It's 4:30 in the morning here , I should try getting some sleep . I don't have anything to test here either , will try it in the morning . – Harsha Venkatram Dec 15 '13 at 23:04
1

I think this is the problem you are experiencing: Track a click on a flash movie (object / embed) with jQuery

That is - the embedded flash object steals the click event, and jquery will never see it.

Community
  • 1
  • 1
andrel
  • 1,134
  • 11
  • 23
0

Do you create the element dynamically? It could be that the element doesn't exist at document ready. Try:

$("body").on("click", "#jwplayer-1_wrapper", function() {
  alert("Handler clicked");
})

Otherwise, check the ID and make sure it's correct.

Daniel Bernhard
  • 382
  • 3
  • 11
-1

You have to wait for the DOM to become ready. Use jQuery(document).ready

$(document).ready(function() {
   $( "#jwplayer-1_wrapper" ).click(function() {
     alert( "Handler Clicked" );
   });
});
hammus
  • 2,602
  • 1
  • 16
  • 36
Pedro Moreira
  • 955
  • 5
  • 8
  • It would make sens, but its not changing any thing, i clic on it on the original full site and it still dont alert me (I'm using this script in a stript injector for chrome) – Samuel Charpentier Dec 15 '13 at 22:32
  • The jQuery(document).ready runs when the page load, so, editing the loaded script won't work, bcuz the page has already loaded – Pedro Moreira Dec 15 '13 at 22:35