0

In jQuery some time '$' making trouble, what is the basic reason ? Answer in detail.

Thanks in Advance

jQuery(function () {
        $("#tabs").tabs();
    });

jQuery(function () {
        jQuery("#tabs").tabs();
    });
Syed Osama
  • 133
  • 1
  • 1
  • 8
  • 2
    http://stackoverflow.com/questions/3291680/jquery-syntax-when-to-use-dollar-vs-jquery – 4b0 Dec 03 '12 at 11:56

4 Answers4

2

its because other library also use $ so there will be conflict use jQuery.noConflict()

jQuery.noConflict();
(function($) { 
  $(function() {
    // more code using $ as alias to jQuery
  });
})(jQuery);

or like

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
1

You might have another library which also makes use of $.

In which case you can make use of jQuery.noConflict.()

var j = jQuery.noConflict();
j(function () {
   j("#tabs").tabs();
});
Curtis
  • 101,612
  • 66
  • 270
  • 352
0

The reason might be conflict with other plugins like prototype for example that also uses the $ sign

kleinohad
  • 5,800
  • 2
  • 26
  • 34
0

The basic reason is that the $ variable is also used by others javascript framework like Prototypejs and Mootools.

So if you want to use both jQuery and Mootools for instance, you should avoid the use of $.

Magus
  • 14,796
  • 3
  • 36
  • 51