views:

85

answers:

4

I was wondering if it was possible to apply effects to retrieved elements within an array.

I know I can output the contents of the array via the: .text() or the .html() functions in jQuery. But I have been trying to fadeIn() the content, and it never works.

How can I accomplish this?

+1  A: 

You must add the object into the DOM before you can show it and use effects on it.

For example:

content.appendTo('#somedivid').hide().fadeIn();
yhager
A: 

You'll have to append it to the dom, hide it and then fade it in:

for(i=0, x=content.length; i<x; i++){      
   $('<p />').text(content[i]).appendTo('#container').hide().fadeIn();
}

Asuming that content is the array of text you you want to add to #container.

Pim Jager
A: 

If each element in the array contain an id which is associated to the element on the page layout you can do:

$('#'+content[i].id).fadeIn();
fmsf
A: 

I'm not sure I understand the question correctly, but it works the same as with the text() or html() functions you mentioned:

var elements = $('.test');
// elements is an array of all elements with class 'test'

// now fade all these elements out:
elements.fadeOut('slow');
M4N