Created
December 26, 2023 06:46
-
-
Save elias1435/4b7157c522f28f6558eb58549c3157fe to your computer and use it in GitHub Desktop.
Remove characters with JS and wrap with the html element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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