I need to link the url from an API and I have tried just about everything I can think of but nothing seems to work. With all the use jQuery has I thought this topic would be covered more. I tried wrap, wrapInner, append, prepend etc.. what am I missing?
Here's the script:
edit: I want to wrap the last list item in the loop but not around the li , inside of it.
<div class="content">
$(document).ready(function(){
$.ajax({
url: "http://api.espn.com/v1/fantasy/football/news/?limit=15",
data: {
// enter your developer api key here
apikey: "wqq7tafpp3ff7ba87ny85n67",
// the type of data you're expecting back from the api
_accept: "application/json"
},
dataType: "jsonp",
success: function(data) {
// create an unordered list of headlines
var ul = $('<div class="fball_group">');
// get headline, desription, and source text
$.each(data.headlines, function() {
var li = $('<div class="fball_hdline">').text(this.headline);
ul.append(li);
var li2 = $('<div class="fball_descrip">').text(this.description);
ul.append(li2);
var li3 = $('<div class="fball_src">').text(this.source);
ul.append(li3);
var li4 = $('<div class="fball_links">').text(this.links.web.href);
ul.append(li4);
});
// append this list to the content div
$('.content').append(ul);
},
error: function() {
alert('There was an error processing the ESPN API');
}
});
});
i have not understood very well what you want but you want make this a link
var li4 = $('<li class="fball_links">').text(this.links.web.href);
you simply create a link tag
link=$("<a/>").setAttr('href',this.links.web.href).text("linkname");
var li4 = $('<li class="fball_links">').append(link);
ul.append(li4);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.