1

Sorry if this sounds weird but i have tried to create a function that checks a variable before executing the remaining jQuery code, it looks something like this:

$(document).ready(function(){
    var myVar = true;

    var myFunction = function(){
        if (myVar) {
            // do something
        };
    };

    $("div").click(function(){
        myFunction();
        $("div).fadeOut("fast");
    });
});

I guess this is not how you implement a function in jQuery so i am a bit lost.

3
  • $("div).fadeOut("fast"); Syntax error, after div need " Commented Mar 21, 2013 at 12:33
  • 2
    Well you forgot the closeing " after div. I don't know if that is a typo or your problem. If that isn't the issue, what errors are you getting? We need more detail than that Commented Mar 21, 2013 at 12:33
  • jQuery is a JavaScript library. You don't write in jQuery, you write JavaScript with jQuery. Commented Mar 21, 2013 at 12:36

2 Answers 2

2

You are missing a double quote in your click handler:

$("div").fadeOut("fast");
Sign up to request clarification or add additional context in comments.

Comments

1
$("div).fadeOut("fast"); 

Syntax error

replace it

$("div").fadeOut("fast");

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.