I ran into a problem that I could not fix myself, so I am asking for your help.
I am trying to replace a string with another string, the replace lines look like this:
- Code: Select all
var word = document.getElementById("word").innerHTML;
document.getElementById("word").innerHTML = wordd.replace(/B/g, '<span class="style106">B</span><span class="style107"> </span>');
It works just perfectly if left alone, but I need to replace every letter inside this string, adding those style and span tags around each and every letter. So if I add another line to this code, like this:
- Code: Select all
var word = document.getElementById("word").innerHTML;
document.getElementById("word").innerHTML = wordd.replace(/B/g, '<span class="style106">B</span><span class="style107"> </span>');
document.getElementById("word").innerHTML = wordd.replace(/C/g, '<span class="style106">C</span><span class="style107"> </span>');
Then it would replace only one of those letters with the given line. For example, it would replace only letter C, but it wouldn't touch the letter B, even though those lines are EXACTLY the same.
I thought it had some problems deciding which line to execute, since they don't have any intervals between them, so I added setTimeout and ran each line with a 5 second delay, but still the result is the same - it replaces only one of the letters (executes only 1 line of code). It doesn't matter how many lines there are, I added the whole alphabet, but it still replaced only one letter.
If there is an alternative solution on how to add tags around a letter inside a string, I would like to hear it.
Please help me solve this problem, this is the only line of code that's keeping me from finishing the whole application.
Thank you!



