Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-22-2012, 05:28 PM   PM User | #1
erebus
New Coder

 
Join Date: Sep 2012
Location: Houston, TX
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
erebus is an unknown quantity at this point
Appending Element with getElementById

Would this be the correct way to utilize innerHTML to append rather then replace

document.getElementById("topstreams").innerHTML +=

i looked it up and it gave this example.. however i cant seem to get it to function... my code for reference

Code:
<script>
function viewallstreams(o)
{
   var base = o.streams;
   if (base.lenght <= 25)
     {
     var streams = base.lenght
     }
   else
     {
     var streams = 25
     }

   for (var i = 0; i < streams; i ++ )
   {
      var status = base[i].channel.status
      if (status.length > 76)
      {
      var status = status.substr(0,76)
      }

      document.getElementById("topstreams").innerHTML += '<div class="image"> <a href="tream.php?stream='+ base[i].channel.name 

+'"><img src="' + base[i].channel.logo + '" alt="" /></a> </div><center><h4><a href="tream.php?stream='+ base[i].channel.name +'">' + 

base[i].channel.name + '</a></h4></center>
<center>' + status +'</center></div>'
   }
}
</script>
The callback if your curios

Code:
<script 
    type="text/javascript" 
    src="https://api.twitch.tv/kraken/streams?game=DayZ&callback=viewallstreams">
</script>
and an example of what the actual HTML that i'm trying to append into the field looks like.. it needs to loop and continue to append to generate a list that is being formatted via CSS

Code:
            <div class="article" id="topstreams">

              <div class="image"> <a href="http://linkurl.com/"><img src="css/images/imgurl.jpg" alt="" /></a> </div>
              <center><h4><a href="http://linkurl.com/">Featured 1</a></h4></center>
	      <center>LLorem ipsum dolor sit amet, consectetur adipisicing elit, sed... </center>

            </div>
erebus is offline   Reply With Quote
Old 10-22-2012, 05:38 PM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 961
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
Originally Posted by erebus View Post
Would this be the correct way to utilize innerHTML to append rather then replace

document.getElementById("topstreams").innerHTML +=

i looked it up and it gave this example.. however i cant seem to get it to function...
Instead of asking others to do the job of the error console, try using the error console.
Logic Ali is offline   Reply With Quote
Old 10-22-2012, 05:59 PM   PM User | #3
erebus
New Coder

 
Join Date: Sep 2012
Location: Houston, TX
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
erebus is an unknown quantity at this point
resolved... When i copied it from my editor to the open copy of the atchual page it somehow added a line break in the middle of the code being inserted... it did not care for this
erebus is offline   Reply With Quote
Old 10-22-2012, 07:22 PM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 961
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
Originally Posted by erebus View Post
resolved... When i copied it from my editor to the open copy of the atchual page it somehow added a line break in the middle of the code being inserted... it did not care for this
So no trouble with the misspelling of 'length'?
Logic Ali is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:54 AM.


Advertisement
Log in to turn off these ads.