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

355
Vistas
jQuery's dollar syntax vs dollar sign JavaScript "convention"

I've read here that for JavaScript there's a "convention" that the $ function be defined as a shortcut for document.getElementById, so I've defined the following function in a <script>,

function $(x) { return document.getElementById(x); }

so I could write $('main') instead of document.getElementById('main'), for instance.

Soon after, when I started looking into jQuery, I found that jQuery uses the syntax $(selector).action() extensively.

However, the two solutions don't seem to work nicely together.

Are indeed the two mutually exclusive? As in, if I use jQuery, I can't use the $ function above, and if I use the latter I can't use jQuery?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use jQuery.noConflict to return control of $. Then, to use jQuery, use jQuery instead of $.

jQuery.noConflict();
jQuery('#main')

You can also assign the returned value of noConflict to an object, and use it just like $:

var a = jQuery.noConflict();
a('#main')
about 4 years ago · Juan Pablo Isaza 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