Detect   and space with JavaScript

你离开我真会死。 提交于 2019-12-01 21:07:51

I found a workaround. Previously, I was using innerHTML to get the contents. Now, I'm using targ.firstChild.nodeValue where targ is the element whose content is needed.Then checking with str.charCodeAt(i)==32 || str.charCodeAt(i)==160 .

This works well.

String.fromCharCode(160) worked for me. It stands for   character. if(str == ' ') was not working in if condition, neither did trim(); but if(str == String.fromCharCode(160)) worked.

For checking normal space use if(str.trim() == '')

Halil Özgür

I think what you are looking is here : non-breaking space in Javascript.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!