Binding dynamically created elements in jQuery

后端 未结 5 1728
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 09:15

The following code is fairly self explanatory, but I am running in to an issue binding the click event to an element that has been created.

You can see at line 25 I

5条回答
  •  心在旅途
    2020-12-11 10:19

     // Overlay click = trigger out
        $('#overlay').click(function () {
            $('#overlay').fadeOut(1000);
            $('.modal').fadeOut(200);
        });
    

    is triggered on page load, when the #overlay element doesn't exist. If you move this piece of code inside the $('a[name=modal]').click(function(e) { part, but after the $('body').append('

    '); part, it should work.

提交回复
热议问题