Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
How to get a div having $ as first character

Suppose i have a div with ID '$abc'. How do i select it using jQuery? Below is the sample code snippet.

function abc(){
	$('#$abc').text('abc')
}
abc();
<script
  src="https://code.jquery.com/jquery-3.1.1.slim.min.js"
  integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc="
  crossorigin="anonymous"></script>
  
  <div id="$abc"></div>

When i try running this i get an error in console like this-

Uncaught Error: Syntax error, unrecognized expression: #$abc
at Function.ga.error (jquery-3.1.1.slim.min.js:2)
at ga.tokenize (jquery-3.1.1.slim.min.js:2)
at ga.select (jquery-3.1.1.slim.min.js:2)
at Function.ga [as find] (jquery-3.1.1.slim.min.js:2)
at r.fn.init.find (jquery-3.1.1.slim.min.js:2)
at r.fn.init (jquery-3.1.1.slim.min.js:2)
at r (jquery-3.1.1.slim.min.js:2)
at abc (fiddle.jshell.net/:46)
at window.onload (fiddle.jshell.net/:48)
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can do it like below:-

function abc(){
 $('div[id="$abc"]').text('abc');
}
abc();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
  
<div id="$abc"></div>

Note:- this is called [attribute|=value] selectors

Reference:- All possible seletors

about 4 years ago · Santiago Trujillo Report

0

you can use this:

$('[id="$abc"]').text('abc');
about 4 years ago · Santiago Trujillo Report

0

You need to escape $ by placing two backslashes in front of it, try the following code:

function abc(){
    $('#\\$abc').text('abc')
}
abc();

Refer to this doc for more info.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!