jeudi 11 janvier 2018

JavaScript if statement fails

So, I have this piece of code:

    var child = document.getElementById(checkboxArray[i]);
    //If the child is currently expanded, we need to close all of his children first
    if(child.name == true)
    {
      alert(child.id + ',' + child.name);
    }

When I get to the if statement, the child.name is true (checked it by alerting it), but it still does not enter the if clause!

I tried changing it to a text and changed the if statement to be:

    var child = document.getElementById(checkboxArray[i]);
    //If the child is currently expanded, we need to close all of his children first
    if(child.name == "enter")
    {
      alert(child.id + ',' + child.name);
    }

Again, I alerted the value of child.name and got "enter", but still it didn't enter the if clause.

I tried changing the if clause from '==' to '===' in both options but it did not work as well.

Any idea why this is happening? Any idea how to fix it?

Thanks

Aucun commentaire:

Enregistrer un commentaire