0

I've this element

<img class="imgclass" src="img.jpg">

And this code

$(document).ready(function() {
$('.imgclass').click(function(){
    alert('Works!!!');
    }); //click
// I need to load something in other moment
$(something).load(function(){
    $('<img src="iamge.jpg">').addClass('imgclass').insertAfter('img');
    });
});

If I click first IMG, it works, but second, nothing. How colud i refresh classes event without copying all the function?

The example: https://jsfiddle.net/q860upLv/2/

Thanks,

lucasgabmoreno
  • 1,001
  • 1
  • 10
  • 18

1 Answers1

0

Read this... about delegation.


Change this:

$('.imgclass').click(function(){

To this:

$(document).on("click", ".imgclass", function(){

Your example.