How dynamically access id of div elements..?

How dynamically access id of div elements..?

i had my work done with this where a,b,c,d are id of some div elements.

        setTimeout(function (){$("#a").fadeIn(300);},0000);
        setTimeout(function (){$("#a").fadeOut(300);},3000);
       
        setTimeout(function (){$("#b").fadeIn(300);},3500);
        setTimeout(function (){$("#b").fadeOut(300);},6500);
       
        setTimeout(function (){$("#c").fadeIn(300);},7000);
        setTimeout(function (){$("#c").fadeOut(300);},11000);
       
        setTimeout(function (){$("#d").fadeIn(300);},11500);
        setTimeout(function (){$("#d").fadeOut(300);},14500);

is there any way where i can combine 4 segments in a dynamic one..?
like:

function do_work(id)
{
      setTimeout(function (){$(id).fadeIn(300);},time);
      setTimeout(function (){$(id).fadeOut(300);},time);
}