# Check is stream is online and change html element

**URL:** <https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297>\
**Category:** API\
**Created:** [May 28, 2016, 3:14am UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297 "2016-05-28T03:14:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jay/32/1761_2.png) [@Jay](https://discuss.dev.twitch.com/u/Jay)\
**Post date:** [May 28, 2016, 3:14am UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297/1 "2016-05-28T03:14:25Z")

</div>

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>
```

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [May 28, 2016, 3:33am UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297/2 "2016-05-28T03:33:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jay](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jay/32/1761_2.png) [@Jay](https://discuss.dev.twitch.com/u/Jay)\
**Post date:** [May 28, 2016, 3:38am UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297/3 "2016-05-28T03:38:35Z")

</div>

The element is not updated I forgot to add the element info

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

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [May 28, 2016, 3:56am UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297/4 "2016-05-28T03:56:49Z")

</div>

You seem to have a typo; twtitchlive in the js vs twitchlive in the html

---

<div class="post-metadata">

**Author:** ![Jay](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jay/32/1761_2.png) [@Jay](https://discuss.dev.twitch.com/u/Jay)\
**Post date:** [May 28, 2016, 4:03am UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297/5 "2016-05-28T04:03:03Z")

</div>

Yes I’ve fixed the typo but this still doesn’t work, thanks for catching that.

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [May 31, 2016, 2:28pm UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297/6 "2016-05-31T14:28:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [June 30, 2016, 2:36pm UTC](https://discuss.dev.twitch.com/t/check-is-stream-is-online-and-change-html-element/6297/7 "2016-06-30T14:36:37Z")

</div>

Closed on June 30, 2016, 2:36pm UTC

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