1

Can someone please explain this to me? I am attempting to do something if key != ''

var key = "";
if($('div[title="Keyword"]').text() != '') {
  key = $('div[title="Keyword"]').text().trim(); 
}

//this always alerts
if (key != '') { alert(key); } 

//this never alerts
if (!key) { alert(key); }
Jonathan Eckman
  • 2,071
  • 3
  • 23
  • 49

1 Answers1

1

I said in the comments it might be an invisible character not stripped by trim. Well, after your further comments, it's clear that's the case. It's the U+200B Zero-width space character. It probably came from jsfiddle (I'm betting you pasted something from there).

bfavaretto
  • 71,580
  • 16
  • 111
  • 150