Hi, during fixing one xhtml page, I found very strange behavior of Google Chrome. There was a placeholder div containing ' ' only. While IE, FF, Opera, Safari gave value of innerHTML as a string (' '), Chrome returned space. That would be OK, but the strange thing is that it is not ordinary space. I mean you cannot use if(the_div.innerHTML == " "), it simply won't evaluate this condition as true. The only way I found around was to use charCodeAt() and check if it's equal 160. Maybe I missed something, that's why I'm asking here if you experienced similar problem, or found some explanation. Is it bug on Chrome, or just design? I also found similar problem here: http://groups.google.com/group/goog...g/browse_thread/thread/7a7071a886163145?pli=1 but with no reply.... Not sure if it's clear what I mean, so here is very basic code sample : <div id="d"> </div> <script type="text/javascript"> var cont=document.getElementById('d').innerHTML; if(cont == ' ') alert('nbsp'); if(cont == ' ') alert('space'); if(cont.charCodeAt() == 160) alert('charCodeAt') </script> Code (markup): Btw. the same behavior is repro using & # 160; Thanks for any ideas, advices.
I got answer on SitePoint, Google Chrome v.2 doesn't have this problem anymore, so just in the case you will need to evaluate , for compatibility remember charCodeAt()