Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

347
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda