Yes, you can certainly call $() with a variable instead of a string literal.
jQuery is just JavaScript, $ is just a function name, and you can always
rewrite:

   alert( 'woot' );

as:

   var woot = 'wo' + 'ot';
   alert( woot );

So you just need to do some debugging.

What are the values of nID and speed? Are they what you expected?

Is the jQuery object returned by $(theID) empty or does it include the DOM
element?

You can check these in Firebug with this code:

   function fadeOut(inID, speed) {
      console.debug( nID, speed );
      var theID = "#" + inID;
      console.debug( $(theID) );
      $(theID).fadeOut(speed);
   }

If you have a valid DOM element, then the problem must lie in the fadeOut
function.

-Mike

> From: Donovan Walker
> 
> i have some code that looks like
> 
>  $("#myID").fadeIn("slow");
> 
> and it works fine, I have some other code that looks like
> 
> function fadeOut(inID, speed) {
>   var theID = "#" + inID;
>   $(theID).fadeOut(speed);
> }
> 
> And it does NOTHING.
> 
> The fadeOut function I wrote because I need to be able to 
> dynamically assign which objects get faded out.  I have NO 
> idea what the objects will be named.
> 
> Why doesn't creating the string 'theID' and using that as the 
> address work?  How do I make it, or something like it work?

Reply via email to