How to find li whose text starts with a particular string?

后端 未结 2 1825
轻奢々
轻奢々 2020-12-20 20:13

I have a function to get the

  • tag at the top that contains the key specified to it, anywhere in the text.

    But I want to have the

  • 相关标签:
    2条回答
    • 2020-12-20 20:36

      Use filter.

      var li = $('.listcontainer ul li').filter(function() { return $(this).text().indexOf(key) === 0; });
      
      0 讨论(0)
    • 2020-12-20 20:50

      Please check filter() in jquery.

      Filter

      Filter demo as specified in api.jquery

       $('li').filter(function(index) {
         return $('strong', this).length == 1;
       }).css('background-color', 'red');​
      
      0 讨论(0)
    提交回复
    热议问题