-1
    $(".closeBtn").on('click',function(){
        alert('');
    });

+function myfunction(){

    $(".elem").on('click',function(){
        $("#someId").html('<img class="closeBtn" src=""/>'
        );
    });

}();

I used html to add some element into somewhere, I checked my dom and things are there. When I click the binded element closeBtn, it doesn't have respond. I thought using on() will work? or it's closure problem?

James Lemon
  • 426
  • 5
  • 17

1 Answers1

0

You need to use:

 $("body").on('click','.closeBtn',function(){
   alert('test');
 });

Check Syntax For event delegation using on

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125