[Twitch-API] List channels again with click button event

[Twitch-API] List channels again with click button event
0.0 0

#1

I’m working on Twitch-API project ( http://codepen.io/raulfm/pen/ZeZVXR ). This function below is executed at page load. But I would like to execute this function again after click button event. I’ve tried, but it doesn’t work.

function listar(usernames, parent) {
  var rows = parent.getElementsByClassName("row");
  if(rows.length > 1) {
    for(var i = 1; i < rows.length; i++) {
      parent.removeChild(rows[i]);
    }
  }
  for(var i = 0; i < usernames.length; i++) {
    getLogo(usernames[i], parent);
  }
}

I set the onclick property to function listar, but it didn’t work.

var allButton = document.getElementById("allbutton");
allButton.onclick = listar;

Why listar function doesn’t execute when I click on button?


#2

I solved my problem doing this:

<button id="allbutton" class="btn btn-default btn-circle all" onclick="listar(usernames, parent)"></button>

I don’t need help anymore. Thanks :wink: