OrchardCMS/OrchardCore · error · Error
Syntax error, unrecognized expression:
Error message
Syntax error, unrecognized expression:
What it means
jQuery's selector engine Sizzle throws this via Sizzle.error() when a selector string cannot be tokenized/parsed by Sizzle.tokenize. It means jQuery received a selector expression (as first arg to $(...) or inside :not(...), find(), etc.) that is syntactically invalid for the selector grammar supported by this jQuery version. The empty message (": ") means the offending expression was an empty string or the error was raised with an empty/whitespace value.
Solutions
- Log/guard the selector before passing to $(): if (!sel || typeof sel !== 'string') return; or console.log the exact string that reaches Sizzle.error.
- Fix the malformed selector string; validate it against standard CSS selector syntax supported by jQuery 3.6.
- If the input may legitimately be empty, check for empty string and skip the lookup instead of calling $().
- If a plugin throws it, update the plugin to a version compatible with jQuery 3.x.
- As a last resort wrap dynamic selector use in try/catch and fall back to a document.querySelectorAll or default behavior.
Example fix
// before
var target = $($el.data('target'));
// after
var sel = $el.data('target');
var $target = (typeof sel === 'string' && sel.trim()) ? $(sel) : $(); Defensive patterns
Strategy: validation
Validate before calling
function isValidSelector(sel) {
return typeof sel === 'string' && sel.trim().length > 0;
}
// usage: if (isValidSelector(sel)) $(sel); else return $(); Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
var $el;
try { $el = $(dynamicSelector); }
catch (e) {
if (/unrecognized expression/.test(e.message)) { $el = $(); }
else throw e;
} Prevention
- Never pass user/attribute-sourced values straight to $(); validate they are non-empty strings first.
- Prefer $(element) references over string selectors whenever you already hold a DOM node.
- Wrap dynamically built selectors in try/catch during development and log the offending string.
- Keep plugins updated for the jQuery major version in use.
When it happens
Trigger: Calling $("") or $(" ") when jQuery falls back to selector parsing; passing a malformed selector like $("div>>"), $("[attr='unterminated") or unsupported pseudo-syntax to $(), .find(), .filter(), .is(), .closest(); passing a non-string (e.g. null coerced to "null" syntax issues) where a selector is expected; building selectors by string concatenation where a variable is empty.
Common situations: Dynamically built selectors from empty form values or missing data attributes; third-party scripts/plugins calling $(element.dataset.target) where the attribute is missing; upgrading jQuery and a previously tolerated selector becomes invalid; typos in complex CSS selectors in templates.
Related errors
- Syntax error, unrecognized expression:
- Syntax error, unrecognized expression:
- Syntax error, unrecognized expression:
- Syntax error, unrecognized expression:
- Syntax error, unrecognized expression:
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/699ec168f2be4ab8.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.6.0/jquery.js:1681
val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
fn( elem, name, !documentIsHTML ) :
undefined;
return val !== undefined ?
val :
support.attributes || !documentIsHTML ?
elem.getAttribute( name ) :
( val = elem.getAttributeNode( name ) ) && val.specified ?
val.value :
null;
};
Sizzle.escape = function( sel ) {
return ( sel + "" ).replace( rcssescape, fcssescape );
};
Sizzle.error = function( msg ) {
throw new Error( "Syntax error, unrecognized expression: " + msg );
};
/**
* Document sorting and removing duplicates
* @param {ArrayLike} results
*/
Sizzle.uniqueSort = function( results ) {
var elem,
duplicates = [],
j = 0,
i = 0;
// Unless we *know* we can detect duplicates, assume their presence
hasDuplicate = !support.detectDuplicates;
sortInput = !support.sortStable && results.slice( 0 );
results.sort( sortOrder );
if ( hasDuplicate ) {View on GitHub (pinned to 4306c0717f)