I know there are many answers on this site, but none of them have helped me solve my problem.That's why I'm going to try to describe it in detail. Please forgive me if it's too long.
I have a software which delivers in an html file a list of words which appear on the screen as:
Paris Berlin Rome Dublin
If I look at the source code of the html file, I can see:
Paris Berlin Rome Dublin
But if, via javascript, I get the content of the span:
var SpanWords = document.getElementById("WordList");
var txtSpanWords = SpanWords.innerHTML;
console.log ("txtSpanWords : " + txtSpanWords)
the result is:
* Paris Berlin Rome Dublin *
I'd like to remove, via javascript, all the non breakable spaces.
I've tried (using, for my tests, £ instead of nothing so that success would be more visible):
1- txtSpanWords.replaceAll(" ","£");
console.log ("txtSpanWords: " + txtSpanWords)
it fails : the string is still the same
2- txtSpanWords.replaceAll(/ /g, "£")
console.log ("txtSpanWords: " + txtSpanWords)
it fails : the string is still the same
3- var regex='/ /g'; txtSpanWords.replaceAll(regex, "£")
console.log ("txtSpanWords: " + txtSpanWords)
it fails : the string is still the same
I also tried to use split:
4- txtSpanWords.split(/\ +/);
console.log (txtSpanWords[0])
leads to &.
And
console.log (txtSpanWords[3])
leads to s.
I really don't understand why.
5- txtSpanWords.split(/[\s\u00A0;\ ]+/);
console.log (txtSpanWords[0])
leads to nothing.
I'll spare you the dozens of other attempts.
Could someone please help me?