I would like to display the letter "w" and "W" in another way on my website with font-feature-settings.
How can I do it dinamically on the entire website in JS?
What I need to add is font-feature-settings: "ss03" 1
;
What I tried now is this. But this convert to paragraph all my text and I dont see any tatx styles anymore:
<script>
document.addEventListener('DOMContentLoaded', function() {
const paragraphs = document.getElementsByTagName('p');
for (let i = 0; i < paragraphs.length; i++) {
const paragraph = paragraphs[i];
const text = paragraph.textContent;
const replacedText = text.replace(/(W|w)/g, '<span class="ss03">$1</span>');
paragraph.innerHTML = replacedText;
}
});
</script>
EDIT: I was able to solve it in this way
// Get all elements on the page
const allElements = document.getElementsByTagName("*");
// Loop through each element to find occurrences of 'w' and 'W'
for (const element of allElements) {
// Check if the element contains the text 'w' or 'W'
if (element.textContent.includes('w') ||
element.textContent.includes('W')) {
// Add the class ".ss03" to the element
element.classList.add('ss03');
}
}