Removing specific element from a list with JQuery

前端 未结 4 594
迷失自我
迷失自我 2021-02-14 10:35

i have a dynamic list, which looks like this:

  • Text1
  • Text2<
4条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 10:42

    You probably have more than one element with the same ID.

    You don't have to use ID at all in case you want to remove them by index you can use the .eq() method:

    $("#btnRemove").click(function() {
        $("#myList li").eq(1).remove();
    });
    

    This will remove the second list item each click.

    Live test case.

提交回复
热议问题