jQuery click on Appended Element not working

后端 未结 5 977

I have an array. I am getting data from Array and using it in jQuery Append to list. But when I am clicking on list item its only showing the last element.

var a         


        
5条回答
  •  花落未央
    2021-01-29 05:03

    you must use this in the click function to refer to the current item clicked from list:

     $(".divClass").on('click', function(e){
    var index = $(this).index();
    var text = $(this).text();
            alert('text: ',text, 'index: ',index);
    e.preventDefault();
        });
    

    Expect this help you.

    tks

提交回复
热议问题