Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

you can use this:

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda