I get this error on a .click() event in jQuery. I see it in Firebug. I use the latest version, 1.3.2 (min)
The click fires an $.ajax() request for a Form in my website. I asked google about this and all he knows is "%" or "[@]" as unrecognized expressions, nothing about the "#".
here is a bit of my code:
$("form#buyForm #submitForm").live("click", function(e) {
var errors = 0;
var inputLastName_value = $("form#buyForm input#userLastName").val();
if (inputLastName_value == "") {
errors = 1;
formErrorHandling("#userLastName");
return false;
}
return false;
});
This way I check all my inputs for errors, and then call formErrorHandling() who does some show/hide, stuff like that, nothing important.
I read that it might be from a selector of mine, but they all seem to be just fine.
Anybody else had the same problem?
Thanks.
From what I can see the exception seems to be somehow triggered by the jScrollPane
plugin you are using.
Try replacing the script you include (v1.2.3 which is as old as from Dec 2008) with a newer version directly from the trunk. Which includes many improvements over v.1.2.3 and fixes the exception for me jScrollPane.js (jScrollPane.min.js minified version of r87 jScrollPane minified with YUICompressor)
removed old answer stuff no longer needed
In some browsers id might be empty and JQuery chokes on "#" as a selector.
Sept 2011
changed from
$(document).ready( function () {
$('#'+id).creatorCall( {init:param} ) ;
} );
to
$(document).ready( function () {
$(this).creatorCall( {init:param} ) ;
} );
and cured that self same uncaught exception: Syntax error, unrecognized expression: #
message
what does the formErrorHandling function look like? Is it expecting a selector or a jQuery object?
perhaps what you need is to call it like
formErrorHandling($("#userLastName"));
I know it's an old issue and there's newer version jScrollPane but as I needed to use current one for due to a legacy issues here's the fix. If you'll use jScrollPane.js from the answer above you need to change the code in line 534:
change:
if (h && h.substr(0, 1) == '#' && h.length > 1) {
to
if (h && h!='#' && h.substr(0, 1) == '#' && h.length > 1) {
Whole chunk of the code responsible for document clicks with the fix:
$(document).bind('click', function(e){
$target = $(e.target);
if ($target.is('a')) {
var h = $target.attr('href');
if (h && h!='#' && h.substr(0, 1) == '#' && h.length > 1) {
setTimeout(function(){
scrollTo(h, !settings.animateToInternalLinks);
}, $.browser.safari ? 100 : 0);
}
}
});
Basically the scrollTo
function will be ignored if link's href
equals #
Cheers
G.
The problem for me seemed to be caused by having one too many # in the selector.
For example:
$('##id_name')
should have been...
$('#id_name')