Twitch API Project help

Twitch API Project help
0

#1

Hello, I’m currently working on the Twitch API project, I think I got the Javascript to work but I would like to sort in my list the online streams to show up first, while relegating the offline placeholders to the bottom of the list.

I didn’t put much effort in the html/css part because I wanted to make the skeleton work first, I will expand on that later, any input on how to “sort” the list? I figure it has to do with sorting the streams array but I can’t think of any way.

This is the link to the project

http://codepen.io/davees/pen/WxoNNY/


#2

Hey, you could create 2 divs (#online and #offline). Then in the json function put an if statement. if(status == "online"){$("#online").append("Whatever html you use")} else append to #offline. In this case you’re also not appending to an h1, which seems a little strange.

EDIT: You only need to add 2 divs and change 2 lines of JS: http://codepen.io/benjaminvanzwienen/pen/GqNMQr


#3

Thank you Ben, very smart idea! About the appending to the h1 you are right it was just a placeholder while experimenting, it is advised to always use IDs as jquery targets right?


#4

If you want to target something specific, it is better to use id’s. By using tags or classes if you ever add another element (same tag or class) you will get strange behaviour.