Send by LINE
B! Bookmarks in Hate-bu
Bookmarks in Pocket
RSS feeds

jQuery: Prevent collision of $

Other language site
No available translations found
Google Translate

jQuery uses $. However, sometimes $ is not recognized as jQuery and it may be an error. That's the solution.

Cause $ collision definition

jQuery uses $. However, this $ may not be recognized as jQuery and a script error may occur.
This happens because there is a JavaScript plugin that uses $ for non jQuery, and a $ definition conflict occurs.

To avoid this, you can solve it by enclosing the code that uses jQuery as follows.

(function($) {
  // Write code using jQuery here.

This means that $ used in function ($) {} has the same meaning as jQuery. In other words, $ explicitly defines jQuery.

When using jQuery you may decide to use (function ($) {}) (jQuery).


You can solve it by rewriting "$" part of jQuery as "jQuery".
However, it is not recommended because this method requires writing "jQuery" every time.

Leave a Reply