Pass values ​​from JSON to html via Jquery

Question:

I'm trying to get the JSON data from twitch and manipulate them in the html, in this case I wanted to assemble a simple list with the online channels, using alert it shows the channels but I thought of printing the list in a ul, I read without having to move in html. Can anyone show me a way to do this?

$.ajax({
 type : "GET",
 dataType : "jsonp",
 url : "https://api.twitch.tv/kraken/streams?limit=25&offset=25",
 success: function(data){
   for(i=0;i<data.streams.length;i++){
   //alert(data.streams[i]._links.self);
   }
 }
});

Answer:

I believe that by "without touching the html" you mean putting the content on the page via javascript, right?

// transforme a lista no que você precisa (lista de li):
var listaDeLi = data.streams.map(function(elemento) {
    return "<li>" + elemento._links.self + "</li>";
});

// coloque o conteúdo gerado em algum lugar
$('#content').append("<ul>" + listaDeLi.join('') + "</ul>");
Scroll to Top