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

339
Views
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 answers
Answer question

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 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!