Removing specific element from a list with JQuery

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

i have a dynamic list, which looks like this:

  • Text1
  • Text2<
4条回答
  •  北海茫月
    2021-02-14 10:40

    You probably had some silly mistake, it should work:

    $('#buttonId').click(function(){
            $('#tl_2').remove();
        });
    

    Note that there is no need to "find" for element by id. id is unique.

    $('li').find('tl_1').remove();  // And you were missing the # anyway...
    

    Make sure you have only one element for each id. id is like id... You can have only one with the same value.

    Each id value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid.

提交回复
热议问题