1

I have a function which is called by moving round on the page, and depending where you are it sends you do a different element.

So

function changeFrame() {
  $('#f2').stop(true,true).hide("blind", { direction: "vertical" }, 400);
 }

Which works great, but I want to change the target ID on the fly, so I though I would be able to call the function with a variable and use that, but it doesn't work.

function changeFrame(requestedFrame) {
      $(requestedFrame).stop(true,true).hide("blind", { direction: "vertical" }, 400);
    }

Everything else is the same, and I have used I have also tried it like this:

  $('requestedFrame')

Lastly, to make sure I am passing it the variable correctly, which I am I did this

    alert(requestedFrame);

Example requestedFrame string

f2
6
  • $('#requestedFrame') not $('requestedFrame') Commented Feb 17, 2013 at 16:13
  • Are you calling the function with changeFrame('#someId') or changeFrame('.someClass') or changeFrame(someElement)? If not, your are doing it wrong. Commented Feb 17, 2013 at 16:14
  • That tries to then go to the element with the id of #requestedFrame not the frame requested through the function variable Commented Feb 17, 2013 at 16:15
  • @FelixKling Yes changeFrame('#someID'); Commented Feb 17, 2013 at 16:16
  • Then it should work. Please create a jsfiddle.net demo which reproduces your problem. Commented Feb 17, 2013 at 16:16

2 Answers 2

2

It's difficult to tell what requestedFrame is, but if it's a string id, then you need to select it with:

$('#' + requestedFrame).stop(true,true).hide("blind", { direction: "vertical" }, 400);

If it's already a jQuery object, then you can drop the wrapper altogether:

requestedFrame.stop(true,true).hide("blind", { direction: "vertical" }, 400);
Sign up to request clarification or add additional context in comments.

1 Comment

requestedFrame is a string such as "f2" short and simple but not an ID/jQuery object
2

$() in jquery accepts objects.. try calling the function like:

changeFrame(this);

and then using this 'obj' variable inside the function:

function changeFrame(obj) {
$(obj).stop(true,true).hide("blind", { direction: "vertical" }, 400);
}

Comments

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.