jQuery - contains()

contains() selects all elements that contain the specified text. The matching text can appear directly within the selected element, in any of that element's descendants, or a combination thereof. As with attribute value selectors, text inside the parentheses of contains() can be written as a bare word or surrounded by quotation marks. The text must have matching case to be selected.

$("li:contains('Sci Fi')").css("text-decoration", "underline", "font-weight", "bold");
  • Aliens - Sci Fi
  • Goonies - Family
  • Interstellar - Sci Fi
  • Lord of the Rings - Fantasy

 

has() selects elements with other elements within them. contains() finds elements with simple text-based matches.