jquery prepend + fadeIn

JqueryAjaxJquery Animate

Jquery Problem Overview


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!

Jquery Solutions


Solution 1 - Jquery

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.

Solution 2 - Jquery

+1 to cletus, but I just wanted to highlight the other way you could do it.

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

Solution 3 - Jquery

Try this: HTML

<button>Add</button>
<div id="data"></div>

Jquery:

$('button').click(function() {
  $('#data').prepend('<div class="item">Test</div>'"');
	$("#data .item:first-child").hide();
   $("#data .item:first-child").fadeIn();
});

Live Demo: jsfiddle

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionyretutaView Question on Stackoverflow
Solution 1 - JquerycletusView Answer on Stackoverflow
Solution 2 - JquerynickfView Answer on Stackoverflow
Solution 3 - JqueryAbhishekView Answer on Stackoverflow