Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use fade in jquery for prepend?

I want to use fade in effect for my prepend function.

I have tried follow one but it is not working.

$('#iq').prepend('.....').fadeIn('slow')
like image 526
w3father Avatar asked Dec 04 '22 22:12

w3father


2 Answers

Try the example below.

$('#test').prepend($('<div id="bob">Hi der</div>').fadeIn('slow'));

Live Demo

Since you are just fading in the elements you are prepending just do it within the prepend as you add them, this also has the benefit of not forcing you to hide them first.

like image 73
Loktar Avatar answered Jan 01 '23 08:01

Loktar


prepend returns the elements in the object you call it on, not the new elements, so you're calling fadeIn on the elements you're pre-pending the new content to. Instead, you want prependTo, which is basically prepend the other way 'round. (See the docs for details.) Also, you need to hide the new elements before fading them in, so:

$('.......').prependTo('#iq').hide().fadeIn('slow');

Live example

like image 23
T.J. Crowder Avatar answered Jan 01 '23 07:01

T.J. Crowder