Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Redact/Hide/Obscure/Mask text content on page with JS
/* Finds text content in some element and redacts it
with the provided mask value
*/
function redactContent(textValue, tagType, maskValue){
for (const tag of document.querySelectorAll(tagType)) {
if (tag.textContent.includes(textValue)) {
tag.textContent = maskValue;
}}
}
// use case: redact pricing on a page
// before: <span>$100.45</span>
// redactContent('$', 'span', 'REDACTED')
// after: <span>REDACTED</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment