I've a problem with a conditional in Js. The logic says that the answer should be false, and according to the console, the statement is false, but when I run it, Js says it's true! It is:
//assume that the value of x is a string different from ''
if(document.getElementById('x').value === ''){
//do some things
}
else{
//do other things
}
When I put on the console
document.getElementById('x').value === ''
it returns false, as spected. When I run, Js deals with it like it was true, jumping to the
//do some things
I tried to make it like
if('' === document.getElementById('x').value)
tried to
var s = document.getElementById('x').value;
if(s.isEmpty())
and also
var s = document.getElementById('x').value;
if(s.equals(''))
but none worked. The code is run way after the DOM has loaded, so it's not like it was trying to check an inexisting element.
Aucun commentaire:
Enregistrer un commentaire