Skip to content Skip to sidebar Skip to footer

How To Find Li Whose Text Starts With A Particular String?

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
  • that starts with the key speci
  • Solution 1:

    Use filter.

    var li = $('.listcontainer ul li').filter(function() { return $(this).text().indexOf(key) === 0; });
    

    Solution 2:

    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');​
    

    Post a Comment for "How To Find Li Whose Text Starts With A Particular String?"