Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

adding a variable



5:16 am on Apr 10, 2011 (gmt 0)

5+ Year Member

It's a primitive bit of scripting, but it works:

function gray() {
$('.A1').animate({color:"#999"}, 400);
setTimeout('$(\'.A1\').animate({color:"#3a3d3f"}, 1600)', 600);
setTimeout('$(\'.A1\').fadeOut(\'100\')', 2600);

So, how to turn the class a variable? I'm halfway there with:

function gray(myclass) {
$(myclass).animate({color:"#999"}, 400);
setTimeout('$(myclass).animate({color:"#3a3d3f"}, 1600)', 600);
setTimeout('$(myclass).fadeOut(\'100\')', 2600);

called with

The first animation fires, but the second and third don't;
FF error console is saying " myclass is not defined " for the second and third lines, but not for the first.

I'm tinkering, but could do with some insight !


8:12 am on Apr 10, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

setTimeout('$(\'' + myclass + '/').animate({color:"#3a3d3f"}, 1600)', 600);


setTimeout(function(){$(myclass).animate({color:"#3a3d3f"}, 1600)}, 600);


10:45 am on Apr 10, 2011 (gmt 0)

5+ Year Member

Many thanks!

setTimeout(function()... works fine and I understand it. Not clear about the forward slash in the first option.


Featured Threads

Hot Threads This Week

Hot Threads This Month