jQuery functions not responding after append()

后端 未结 3 1535
故里飘歌
故里飘歌 2020-12-19 04:47

I\'m creating a series of div boxes that lets users add/remove items from each box with jQuery. I find that after I add a new element to a box, the click function I have bou

3条回答
  •  心在旅途
    2020-12-19 04:55

    It's because when your code runs, the items aren't added yet. You need to add the remove click function to be dynamically assigned to your new block after you add it during the add click function.

    $(".add").click(function() {
      $("#targetbox").append("This element was added");
      // Add code here for .remove click function
    });
    

提交回复
热议问题