1

Here's my code:

function mouseOver(variable)
{
    return function()
    {
        $(variable).fadeIn(100);
    };
}

function mouseOut(variable)
{
    return function()
    {
        $(variable).fadeOut(100);
    };
}

function lawyer(var1, var2, var3, var4)
{
    return function()
    {
        $(var1).bind('mouseenter', mouseOver(var2)).bind('mouseleave', mouseOut(var2)).click(
        function()
        {
            $(var1).unbind('mouseenter').unbind('mouseleave');
            $(var1).removeClass('off').addClass('on');

            $(var3).bind('mouseenter', mouseOver(var4)).bind('mouseleave', mouseOut(var4));
            $(var3).removeClass('on').addClass('off');

            $(var4).hide();
        });
    }
}

lawyer("#group", ".b", "#group2", ".l");

What would be the reason for this not working?

It works in that it hides $(var4).hide();, but clicking on the object doesn't seem to do anything. It works if I take the code out of a function and just copy/paste it a few times and change the targets. I'm not seeing it... Any help would be appreciated!

2
  • 1
    Try adding an execution operator at the end of the lawyer call: lawyer("#group", ".b", "#group2", ".l")(); Or just don't have lawyer() return a function by unwrapping the code from the function returned. Commented Jun 7, 2010 at 1:52
  • Thanks Patrick. Both of those solutions worked, but I just unwrapped my code from the function return. Not sure why I was doing that. But thanks! Commented Jun 7, 2010 at 2:20

2 Answers 2

2

It's unclear to me why you're returning a new function from lawyer(). Your call to lawyer(...) does not execute the returned function. Could that be the reason?

One technique I use often to determine whether some particular bit of code is even being run at all, is to insert an alert("hi") or something in there. If you don't see the alert, the code isn't being run.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

function lawyer(var1, var2, var3, var4) {
    return function() {
        $(var1)
            .bind('mouseenter', function() { mouseOver(var2); })
            .bind('mouseleave', function() { mouseOut(var2); })
            .click(function() {
                $(var1).unbind('mouseenter').unbind('mouseleave');
                $(var1).removeClass('off').addClass('on');

                $(var3).
                    bind('mouseenter', function() { mouseOver(var4) })
                    .bind('mouseleave', function() { mouseOut(var4) });
                $(var3).removeClass('on').addClass('off');

                $(var4).hide();
            });
    }
};

lawyer("#group", ".b", "#group2", ".l")();

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.