Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to evaluate   in a string? [duplicate]

console.log(document.getElementById('wsk').textContent === "CASE ");
console.log(document.getElementById('wsk').textContent === "CASE ");
<span id="wsk">CASE&nbsp;</span>

Why are the above log both output false? How should I write the value in 3rd and 4th line so it can evaluates to true?

And by the way, on my page if I replace the "$nbsp;" in the span with a real space, it won't get displayed, why?

like image 657
shenkwen Avatar asked Jan 19 '18 13:01

shenkwen


1 Answers

A non-breaking space (0xA0) is not a normal space (0x20)

Try comparing the actual character:

document.getElementById('wsk').textContent === 'CASE\xA0'
like image 109
Tim Avatar answered Oct 03 '22 08:10

Tim