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 7734251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:12:13+00:00 2026-06-01T07:12:13+00:00

I struggle to use a jquery selector containing brakcets. Basically I parse a JSON

  • 0

I struggle to use a jquery selector containing brakcets.
Basically I parse a JSON response from the server in my jquery code. Then I iterate over the object, once the parsing is done.

This object has such a structure:

  errors = {
   input#title_id: "error message",
   select#authors_id[]: "error message 2"
  }

Then I iterate over this map like follow:

$.each(errors, function(fieldSelector,errMsg){
  fieldSelector = fieldSelector.replace('[','\\\\[');
  fieldSelector = fieldSelector.replace(']','\\\\]');
  $(fieldSelector).hide(); //for the example
}

Everything works well except for the select that has an id with brackets!

  • 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-01T07:12:14+00:00Added an answer on June 1, 2026 at 7:12 am

    Per the jQuery Selector documentation, you need to use two brackets to escape meta-characters:

    If you wish to use any of the meta-characters ( such as
    !"#$%&'()*+,./:;<=>?@[\]^{|}~ ) as a literal part of a name,
    you must escape the character with two backslashes: \\.
    For example, if you have an element with id="foo.bar", you can
    use the selector $("#foo\\.bar").

    But the double brackets are only required so that a single bracket char \ is present in the selector string. The selector engine then uses that bracket later on to escape the meta character. Anyway, this means that your code also only needs to use two brackets – there is no need to provide an extra level of escaping:

    $.each(errors, function(fieldSelector,errMsg){
        fieldSelector = fieldSelector.replace('[','\\[');
        fieldSelector = fieldSelector.replace(']','\\]');
        $(fieldSelector).hide(); //for the example
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some struggle with smooks bean binding and CSV mapping, I managed to parse
I had a bit of a struggle trying to understand why my code was
I struggle to write Makefiles and I'm building up some examples to learn from.
I frequently encounter a code smell when I use the Enumerable group_by method. Some
I am currently developing .NET code and am using VS2010. One thing I struggle
I've deployed, after some struggle, a web-app on a (remote) Tomcat 5.5 server (Turnkey
I struggle to create directory names containing Unicode . I am on Windows XP
I struggle on a System.OutOfMemoryException when performing an import process where a lot of
I struggle a little with the understanding of generics and how they can and
I struggle with finding a good medium on communication. In our jobs, it seems

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.