append() not working in safari but works in IE6
I having trouble getting append()
to work in safari for some reason, but it works fine in IE6 !! The problem I have got is $( "#newsList .newsItemHeading" ).each(function(){})
and
$( "#newsList .ne开发者_StackOverflow社区wsListItem" ).each(function(){})
is not working. I tried displaying the content in the <ul id="newsList">
in safari in an alert box,it was returning blank.
Its just that iam not able to access the elements in jquery i have added using the apend(),but the elements are picking the CSS style perfectly.Am i missing somethin here? Or should i be using some other technique?
Html:
<html>
<div class="news-container">
<ul id="newsList">
</ul>
</div>
</html>
jQuery:
$.ajax({
url: 'news.htm',
type: 'GET',
dataType: 'html',
success: function(data){
var $content = $(data).find('.newsItemContent');
$content.each(function(){
var li = $("<li>"+"<div class=newsItemHeading>"+$(this).children("h1").text()+"</div>"+"<div class=newsListItem>"+$(this).clone().children("h1").remove().end().text()+"</div>"+"</li>");
$("#newsList").append(li);
});
}
});
$( "#newsList .newsItemHeading" ).each(function(){
$(this).bind('click', function() {
window.location.href='news.htm';
});
});
$( "#newsList .newsListItem" ).each(function(){
$(this).html($(this).html().substring(0,135)+'<a href="news.htm">...</a>');
});
If the question is not clear enuf,please let me know.i cud provide more details if needed so it makes it easier to understand what the problem is
I would say, that the two each-functions at the end work, but that the ajax-request that adds the list-items is "too slow" and the functions will be evaluated before there are list-elements. So the selectors match 0 elements.
Tried getting $( "#newsList .newsItemHeading" ).length
to know how many elements there are?
精彩评论