jquery remove list item where .text() = 'blabla'

后端 未结 3 946
后悔当初
后悔当初 2020-12-11 01:31

I have the following structure

  • something
  • ...
  • blabla
  • <
3条回答
  •  我在风中等你
    2020-12-11 01:56

    $('li > a:contains("blabla")').remove();
    

    Have a look at the :contains selector.

    I've just noticed that :contains does partial matching. You may need to do...

    $('li > a:contains("blabla")').each(function() {
         if ($(this).text() === 'blabla') {
             $(this).parent().remove();
         }
    });
    

    You could also make the selector less strict if doing it that way.

    ... or you could do it much neater like Nick Craver.

提交回复
热议问题