1

I have buttons with a class named nav, when a button is clicked the ID is read and the variable "pre" is set to the ID. Once the variable is set I'm removing part of the id, "-link". This part is working fine but could be where my problem is being created. Once "-link" has been removed I'm trying to use the remainder of pre to target the id of a div on the page and animate it. So I use another variable to hack together...

curr = '$("#'+pre+'")';

This "appears" to create what I need but when I target curr in my animation nothing happens. Probably b/c I have created a string and this is where my knowledge begins to fade.

Below is the complete function. I plan to use this with multiple buttons that have corresponding div's so it would be nice to use a single function for the whole class.

var pre = null;
var curr = null;     
$('.nav').click(function(){
               pre = $(this).attr("id");
               pre = pre.substring(0, pre.indexOf("-link"));
               curr = '$("#'+pre+'")';
               alert(curr);
                curr.animate({opacity:1}, {
                   duration:250,
                   queue:true,
                   complete:function(){
                     //  alert("calling moveOld");
                       moveOld();
                       }
               });

           });

1 Answer 1

3

You don't need the quotes around it, that's the problem.

$('#'+ pre)
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, over complication on my end. Thanks for setting me straight, works perfectly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.