jQuery “not contains” selector

前端 未结 3 1972
春和景丽
春和景丽 2020-12-16 09:33

The :contains() jQuery selector allows you to match find elements that contain a specified string of text. What I want to do seems related: I\'m providing the user a \"filt

相关标签:
3条回答
  • 2020-12-16 09:45

    Let say that you want the list of all <td> that dont contains string 'Dinesh'.(assuming Dinesh is inside name Attribute)

    $('tableId > tbody > tr > td').not("[name*='Dinesh']")
    
    0 讨论(0)
  • 2020-12-16 09:53

    Use this:

    $("div:not(:contains('John'))").css("text-decoration", "underline");
    
    0 讨论(0)
  • 2020-12-16 10:02

    Assuming your user's text is stored in a variable called userString:

    $(':not(:contains('+ userString +'))').hide(); 
    

    will hide all of the elements not containing that string.

    Edit: If you have control over the elements in the list items, you could transform the user's text when you store it in the userString var.

    0 讨论(0)
提交回复
热议问题