Skip to content

Instantly share code, notes, and snippets.

@elias1435
Created December 26, 2023 06:46
Show Gist options
  • Save elias1435/4b7157c522f28f6558eb58549c3157fe to your computer and use it in GitHub Desktop.
Save elias1435/4b7157c522f28f6558eb58549c3157fe to your computer and use it in GitHub Desktop.
Remove characters with JS and wrap with the html element
// Get all elements with the selector '.variation-Option div'
const elements = document.querySelectorAll('.variation-Option div');
// Iterate through each element and remove "(", "+", and ")" excluding content inside <span>
elements.forEach(element => {
// Iterate through child nodes of the element
for (let i = 0; i < element.childNodes.length; i++) {
const node = element.childNodes[i];
// Check if the node is a text node and not inside a <span>
if (node.nodeType === Node.TEXT_NODE && !node.parentNode.matches('span')) {
// Replace "(", "+", and ")" with an empty string
node.textContent = node.textContent.replace(/[()+]/g, '');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment