Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:46:31+00:00 2026-06-09T23:46:31+00:00

When I do var foo = $(‘n’); console.log(foo); I get jQuery object. However if

  • 0

When I do

var foo = $('n');
console.log(foo);

I get jQuery object. However if I do:

var bar = $(' ');
console.log(bar);

then I get “Syntax error, unrecognized expression:  ” error message in Firefox.

Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:46:33+00:00Added an answer on June 9, 2026 at 11:46 pm

    If the arguments to the jQuery object are a string, it must either be a valid CSS selector or some detectable HTML tags. Since it is not detectable HTML tags (there are no HTML tags in your string that are surrounded by < and >), then it tries to process the string as a CSS selector.

    But the Sizzle selector engine inside of jQuery finds that it is in invalid CSS selector and it throws an exception. You can see this code inside of jQuery that is getting triggered:

    Sizzle.error = function( msg ) {
        throw new Error( "Syntax error, unrecognized expression: " + msg );
    };
    

    Though '&nbsp;' is a valid snippet of HTML, jQuery has to be able tell whether you are trying to pass a CSS selector or some HTML tags. To do that, it looks for the open and close tag characters < and > in a typical place for HTML tags in order to distinguish between HTML and a CSS selector. In your case, you fail that test so it tries to process your string as a CSS selector (which it is not) so it fails.

    You need to pass valid arguments to jQuery. If you want to pass some HTML to it, you can do this:

    var bar = $('<span>&nbsp;</span>');
    

    The reason that this works:

    var foo = $('n');
    console.log(foo);
    

    Is that 'n' is a valid CSS selector. It probably won’t match anything in your document unless you have <n> tags in your document, but it is a valid CSS selector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var foo = 'bar'; console.log(window.foo); // bar Seems like variables get assigned as properties
Given: function foo(){ var bar = quux; console.log(/*mystery code here*/); } I'm looking for
If you execute this code: var foo = {bar: 'baz'}; window.console.log(foo); foo.bar = 'bla';
I have: var foo = '(bar)' foo.replace('(', '').replace(')', '') So, I get bar without
Assign object literal properties var foo = { bar : 'hello'}; Ternary var cats
var foo = 'hello'; var myfunc = function() { console.log(foo); var foo = foo
If I declare an object as follows: var foo.bar = new Object; Does that
If I have a JS object like: var foo = { 'bar' : 'baz'
I have this object, dive : var dive = new Foo.Bar(); And Foo.Bar looks
var foo = { p1: function(){ return this.p2; }, p2: function(){ console.log('i am foo.p2');

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.