samedi 1 octobre 2016

variable use in conditional not working?

So I have 10 of these in my HTML:

<div class="resultContainer">
   <div class="twitchResult" id="charionna">
      <a class="link" href="http://ift.tt/2dgDQuf"target="_blank">
         <h3 class="username">charionna</h3>
         <p class="streamInfo"></p>
      </a>
   </div>
</div>

When I make an request to the Twitch API and the server responds with a non-200 status code I have the response handler function run the "callSuccessChecker" function like this:

function twitchInfo() {


     // request NOT succesful
     if(this.readyState == 4 && this.status !== 200) {

     //  console.log('This is working');

     callSuccessChecker();

     }
}

This part is working just fine.

It's the "callSuccessChecker" that's an issue. Specifically, using a variable that's I declared in it in a conditional. Like so:

function callSuccessChecker() {

      var containerList = document.getElementsByClassName('resultContainer');
      var closedText = document.createTextNode('account closed');

      for (i = 0; i < 10; i++) {// <--------not working YET

          if(containerList[i].style.backgroundColor == '#F5D16B') {

          containerList[i].children[0].children[0].children[1].appendChild(closedText);
          }
     // console.log (containerList[i].children[0].children[0].children[1]);
}

}

In this function you can see I have commented out a console.log at the bottom. When I use "containerList[i]" here, it shows me the output in the console.

But when I do the same thing (as is visible in the function) inside the "if" conditional and object, it doesn't seem to work/activate/grab it/whatever the correct term for that is.

Any explanations as to why this is?

Is it the conditional itself that is off?

Help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire