views:

100

answers:

3

I've got this (remarkably) simple JavaScript function that is called when a user clicks a "Cancel" link:

function hideNewUserPanel(){
    $('#create_user_panel').slideUp('slow');
    $('.right_interior_panel').slideDown('slow');
}

And the code to add the handler:

$(function(){
    $('#cancel_create_user_btn').live('click', 
        function(){ hideNewUserPanel(); }
     )
});

Functionally, everything works as expected. Trouble is, when I click the "Cancel" link, Firebug shows an error in the console:

uncaught exception: Syntax error, unrecognized expression: #

I've stepped through the code several times and the error appears at some point before the call to hideNewUserPanel(). At the risk of sounding like one of "those programmers" (the kind that claim to have found a bug in GCC and assume their own code is perfect), the exception is being thrown from somewhere within jQuery proper, so I assume the issue is in there. I'm using jQuery 1.3.2 (this is a legacy project using many jQuery plugins that will break if we update to 1.4.x).

Is there anything obviously wrong with my code that I'm simply not seeing? This code is, frankly, very simple and I don't really see what the issue could be.

Thanks!

+4  A: 

This:

$(function(){
    $('#cancel_create_user_btn').live('click', 
        function(){ hideNewUserPanel(); }
});

Needs a closing paren after the function, like this:

$(function(){
    $('#cancel_create_user_btn').live('click', 
        function(){ hideNewUserPanel(); });
});

Also, you can write that a bit simpler :), try this:

$(function(){
    $('#cancel_create_user_btn').live('click', hideNewUserPanel);
});
Nick Craver
*paren, not parent, methinks...
Matt Ball
Crap - that's a transcription error, actually. That closing paren does appear in the code, I just neglected to add it in my question. I'll update the question.
inkedmn
The thing is, wouldn't that generate a syntax error when the script block is parsed, and not later on? I'm wondering whether there's something getting confused inside the selector engine.
Pointy
@Bears - Woops, fixed
Nick Craver
@Pointy - It looks like he has a `$("#")` going on somewhere, but not in the posted code...
Nick Craver
+1  A: 

You seem to be msising the end of the live call:

$(function(){
    $('#cancel_create_user_btn').live('click', 
        function(){ hideNewUserPanel(); }
    ); // <===
});
T.J. Crowder
A: 
$(function() {

        function hideNewUserPanel() {
            $('#create_user_panel').slideUp('slow');
            $('.right_interior_panel').slideDown('slow');
        }

        $('#cancel_create_user_btn').live('click', function() { hideNewUserPanel(); });



    });
XGreen