52

I have this code:

$.ajax({
        url : url,
        data : {ids : JSON.stringify(jsonids), hotel_id: hotel_id},
        success : function(response)
        {
            $('#be-images ul').prepend(response).fadeIn('slow');
        },
        dataType: 'html'
    });

but the fade In does not work...I want the content to be prepended and faded in...how will I do this?

Thanks in advance!

Crescent Fresh
  • 115,249
  • 25
  • 154
  • 140
yretuta
  • 7,963
  • 17
  • 80
  • 151

3 Answers3

111

Assuming response is HTML then try this:

$(response).hide().prependTo("#be-images ul").fadeIn("slow");

When you do it this way:

$('#be-images ul').prepend(response).fadeIn('slow');

the thing you're actually fading in is the result of the initial selector (the list at the front), which is already visible.

cletus
  • 616,129
  • 168
  • 910
  • 942
  • both cletus and nick, your ways are awesome.. i stumbled upon the same problem and both of your ways work like a breeze... thanks... – coder101 Feb 11 '13 at 14:12
  • @cletus : I've same problem but my data is json array. I uses .each function and trying to prepend but it doesn't show any data prepending - `var li = '
  • '+item.img+'
  • ';$('.twitter-list').prepend(li).hide().fadeIn("fast");` – Vilas Jun 07 '16 at 05:10