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开发者_JAVA百科 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!
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);
});
You seem to be msising the end of the live
call:
$(function(){
$('#cancel_create_user_btn').live('click',
function(){ hideNewUserPanel(); }
); // <===
});
$(function() {
function hideNewUserPanel() {
$('#create_user_panel').slideUp('slow');
$('.right_interior_panel').slideDown('slow');
}
$('#cancel_create_user_btn').live('click', function() { hideNewUserPanel(); });
});
精彩评论