hide-if-contains
The hide-if-contains snippet hides any HTML element (or its ancestors) that match a CSS selector if the element's text contains a given string.
You can use hide-if-contains to hide elements based on their text content.
Parameters
search
The string to look for in HTML elements. If the string begins and ends with a slash (/), the text in between is treated as a regular expression.
Yes
selector
The CSS selector that an HTML element must match for it to be hidden.
Yes
searchSelector
The CSS selector that an HTML element containing the given string must match. Defaults to the value of the selector argument.
No
Filter examples
The following table lists examples that use the hide-if-contains snippet:
hide-if-contains FAQ nav
Hides any nav element whose text content contains the word FAQ. The word FAQ doesn't need to be found inside the direct children of the nav element; it can be anywhere in its subtree.
hide-if-contains FAQ nav a
Hides any nav element that has an a element inside its subtree whose text content contains the word FAQ.
hide-if-contains /.*/ li.serp-item 'li.serp-item div.label'
Hides any li.serp-item element that has an 'li.serp-item div.label' element inside its subtree whose text content matches the /.*/ regular expression.
Last updated
Was this helpful?