I am trying to color a specific part of a string, this is what I have so far:
function SpecialColor(num) {
const color = document.getElementById(`alignColor${num}`).value;
let realnum = num - 1;
const input = document.getElementById("rolealign");
const splited = input.innerHTML.split(" ");
let result = input.innerHTML;
let winner = splited[realnum];
result.replace(winner, `<span style="color:${color};"> ${winner} <span>`);
console.log(result);
input.innerHTML = result;
}
Let's say the string is Miki Mouse
.
Nothing happens.
result - Stays as Miki Mouse
winner - Miki
splited - ["Miki", "Mouse"]
color - A value taken of out a color input.
Can someone please explain to me why my code doesn't work, and point me out to some other soultions? Thanks.