Jquery $("img").click(function() selector not working

the img isn't in the DOM when your event handler is registered. you can use $('body').on('click','img',function(){alert('it works');})


Rather than run your code in document.ready(), you should use window.load() function instead.

$(window).load(function() {
    $("img").click(function(){
        alert("it works!");
     });
});
  • document.ready() is a jQuery event, it runs when the DOM is ready, e.g. all elements are there to be found/used, but not necessarily all content.
  • window.load() fires later (or at the same time in the worst/failing cases) when images and such are loaded, so if you're using image dimensions for example, you often want to use this instead.

 $(document).ready(function(){
    $(".Image").click(function(){
    alert("it works!");
   });
  });

IF you want your code to work with out change just put .Image not img the class name not attribue name