I want to color all / and + signs in the given text so I tried this:
const grammarStructure = document.querySelector(".grammar-structure");
grammarStructure.innerHTML = getColoredStructure("have / has + been + ing");
function getColoredStructure(text) {
let result = text;
result = result.replaceAll('+', "<span class='action'>+</span>");
result = result.replaceAll('/', "<span class='action'>/</span>");
return result;
}
.action {
color: #ff0033;
}
<div class="grammar-structure"></div>
But as you see it doesn't work correctly! I guess the / sign in each span is replaced too and that causes the issue...
How can I fix this?