Reputation: 21003
Due to circumstances out of my control, SharePoint, I have the following piece of code.
var item = $('<span><font size=1> </font></span>').text()
I am trying to compare the .text()
value to
and don't know what to do. Stepping through the code item
seems to equal " " which makes sense. But doing item == " "
returns false. How should this comparison be done?
EDIT: Example fiddle
Upvotes: 17
Views: 15678
Reputation: 318518
Try checking for '\xa0'
(which is the character created by
):
var item = $("<span><font size=1> </font></span>").text();
alert("'" + item + "' " + (item == '\xa0'));
Upvotes: 46
Reputation: 7489
Compare it to
, as that is the content you want to match. It appears not to be that because the browser renders is as space, rather than characters. Comparing it to
should result in either two sets of
s being compared, or two identical spaces being compared.
Upvotes: 0