Jquery error uncaught exception Syntax error unrecognized expression
Causes
What causes this error?
"Uncaught exception: Syntax error, unrecognized expression"
- Your selector didn't match any elements of the DOM
- You are looping through objects using a selector that is not always true
- Selector is in the wrong format -- see "Selector Syntax" further down the page
Good Code
// Selecting all input values of a div
$('#div_id input').each(function()
{
if(this.id)
{
fields_to_save.push(this.id);
}
});
Bad Code
// Selecting all input values of a div
$('#div_id input').each(function()
{
fields_to_save.push(this.id);
});
Selector Syntax
This happens mainly because the older versions of jQuery had different syntax.
Good Code
$("input[id=name]").val();
Bad Code
$("input[@id=name]").val();// Old style
See detailed documentation for good jQuery syntax formats.
Solution for Syntax Errors