adding onclick event to dynamically generated array of element jquery

后端 未结 3 880
北恋
北恋 2021-01-28 11:30

I have a dynamically generated thumbnail images on the left side of my popup and on click of the image i want that image to be displayed on the right hand side.

I am usi

3条回答
  •  情书的邮戳
    2021-01-28 12:03

    Try event delegation approach here where in the events are associated to the elements ancestor ..

    By doing so because of bubbling effect the click event will be associated to the image element in such cases...

    $(".photoright").on('click', 'img', function(){
       alert(this);
    });
    

    Make sure the id in your document is unique.

    So instead of id="citythumb" declare class="citythumb"

提交回复
热议问题