Jay
May 28, 2016, 3:14am
1
Hey, So I want to know how I can check if a stream is online and if that stream is online change a html element to say where the stream is online.
Here is what I have JS
$.getJSON("https://api.twitch.tv/kraken/streams/{streamname}?callback=?").done(function(data) {
if(data.stream) {
online();
var element = document.getElementById("twtitchlive");
element.innerHTML = "We are live!"
console.log(data)
}
else {
offline();
}
});
EDIT:
Html element
<li><a><span id="twitchlive"></span>Test</a></li>
The code looks good to me. What’s the problem?
Jay
May 28, 2016, 3:38am
3
The element is not updated I forgot to add the element info
<li><a><span id="twitchlive"></span>Test</a></li>
You seem to have a typo; twtitchlive in the js vs twitchlive in the html
Jay
May 28, 2016, 4:03am
5
Yes I’ve fixed the typo but this still doesn’t work, thanks for catching that.
What are the values when you debug and step into the if(data.streams)
clause? Does the span exist when this code is running (i.e. after a document ready or this code at the end of the document)?
system
Closed
June 30, 2016, 2:36pm
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.