-1

I have an .js file that has certain functions:

$(function(){
 function slideDown(class) {
 var className = class;
 $('.slide_' + className).slideDown('slow', function() {
 });
 }
});

(And yes i added the .js file in the heading and it's showing in the firebug console.)

And i got an link that calls the function:

<a href="#" onclick="slideDown('.$x.');" class="info">i</a>

But when i press the button my firebug gives the following error:

ReferenceError: slideDown is not defined

So what am i doing wrong?

Robert Karl
7,8666 gold badges42 silver badges61 bronze badges
asked Oct 26, 2012 at 7:21
4
  • 2
    Why are you using onclick on the markup when you're using jQuery? Seems contradictory... Commented Oct 26, 2012 at 7:23
  • slideDown is defined only within your jQuery ready() callback. Commented Oct 26, 2012 at 7:23
  • Im using onclick cause i have multiple links in that container and definining the certain link would mean alot of text, but i guess both options would be alright? Commented Oct 26, 2012 at 7:24
  • I recommend to use the jQuery selectors. In your ready() jQuery function just use $(".info").click(slideDown) Commented Oct 26, 2012 at 7:25

3 Answers 3

2

You are declaring slideDown in another function so it is only available inside that function, declare it outside the function so it will have global scope.

answered Oct 26, 2012 at 7:23
Sign up to request clarification or add additional context in comments.

Comments

1

There is an error with the variable class. Please use another variable name

Error: class is a reserved identifier

answered Oct 26, 2012 at 7:24

1 Comment

This was one of the problems, but the declaring outside an other function was the biggest problem so im gone mark that as an answer. But i would like to thank you for this answer!
0

$x is undefined, i guess this code is for php

<a href="#" onclick="slideDown('<?=$x?>');" class="info">i</a>
answered Oct 26, 2012 at 7:34

1 Comment

$x isn't undefined it's part of the total code, but thanks for your input.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.