I currently have this function to fetch youtube videos:
function searchYouTube(searchstringYT, white2)
{
var yt_url = 'http://gdata.youtube.com/feeds/api/videos?q=' + searchstringYT + '&format=5&max-results=1&v=2&alt=jsonc';
$.ajax({
url : yt_url,
dataType : "jsonp",
success: function (json)
{
var result= json.data.items;
for (i in result)
{
if (result[i].title.toLowerCase().indexOf("live") >= 0)
{
$(".whiteDiv2").html("");
$("<h2/>").text("LIVE")
.appendTo(white2);
$("<h3/>")
.text(result[i].title)
.appendTo(white2);
$("<iframe/>")
.attr("src","http://www.youtube.com/embed/"+result[i].id)
.css({
"width":"620",
"height":"400"
})
.appendTo(white2);
}
}
}
});
}
Problem is: I do this with a for loop, but I only need to do it for one video.. My question is: how do I remove the for loop, since I only need to run this loop once?
Also for some weird reason: if I add a else{} to my if(result..) function, the else is always executed, it just skips the above part. With the else left out, it always does the if part though...