views:

48

answers:

1

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 .newsListItem" ).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

A: 

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?

alopix
@alopix since there are three div with class .newItemHeading its returning 3 in IE6 and 0 in safari.The two each functions were working earlier in safari,it stopped working when i started to build that list using ajax. i dont understand why it works in IE 6 and not in safari !!
manraj82
Is the page valid? Try it with a static <li><div class="newsItemHeading">something</div></li> from the beginning
alopix
tried that it works on the static list items,it always did,the problem started after i tried to do it dynamically...its like u said "ajax-request that adds the list-items is "too slow" and the functions will be evaluated before there are list-elements.
manraj82
Then call the functions in the ajax request's success-function ;)
alopix
ooooh yes,i cud hav done that !! cheers dude
manraj82