Ok so I'm pulling in a jsonp feed with jquery and then trying to format my widget to work with the data.
I have it 90% working but I can't figure out the how to get a <a href="">
to have the value of my link that is "item.url" in my jsonp.
I know I'm missing some code for the "var url= $('<div>').attr("href",item.url);"
part but I cn't for the lif开发者_JAVA百科e of me figure out how to get it to work! :(
Here is my code:
gv_responce = function (response) {
// we destroy the script element.
scriptElement.parentNode.removeChild(scriptElement);
//we have all the information in response variable in a json format,
//we just format the results.
for (keyItem in response.posts) {
var item = response.posts[keyItem];
var img = $('<img>').attr('src', item.thumbnail);
var div = $('<div>').append(img);
var title = $('<div>').html($.trim(item.title));
var text = $('<div>').html($.trim(item.excerpt));
var url = $('<div>').attr("href", item.url);
div.append(title);
div.append(text);
div.attr('class', 'gv');
$('#content').append(item.from_user);
$('#content').append(div);
}
}
})();
//when everything is loaded we call the api ...
jQuery(document).ready(LKS.makeRequest());
Shouldn't
var url = $('<div>').attr("href", item.url);
be
var url = $('<a>').attr("href", item.url);
I think you need to replace the line
var url = $('<div>').attr("href", item.url);
with
var url = $('<a>').attr("href", item.url);
afterwards, you'll want to add the to your DOM
$('#content').append(url);
You should write something in 'a' tag's html. You have also created 'a' tag but you just couldn't see.
try this;
var url= $('<a>').attr("href",item.url).html('itemName');
instead of
var url= $('<a>').attr("href",item.url);
精彩评论