Check is stream is online and change html element

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("{streamname}?callback=?").done(function(data) {
    if( {
        var element = document.getElementById("twtitchlive");
        element.innerHTML = "We are live!"
    else {

Html element

<li><a><span id="twitchlive"></span>Test</a></li>

The code looks good to me. What’s the problem?

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

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)?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.