The console gives this error:

Uncaught TypeError: $ is not a function at profile.php?id=1:122 

I tried it in an empty .php file, everything works fine there, I concluded that some internal script interferes with the work. $.noConflict(); did not help. How to solve this problem?

PHP file:

 <!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript" src="/engine/smiles/emojionearea.js"></script> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> 

Styles and other non-script entries are omitted in <head> .

All connected modules respond Response code: 200 .

The script itself:

 <div class="box-v5 panel"> <script type="text/javascript"> $.noConflict(); $(document).ready(function() { //Π’Π° самая строчка, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ругаСтся консоль $("#emojionearea1").emojioneArea({ pickerPosition: "left", tonesStyle: "bullet" }); }); </script> <div class="panel-heading padding-0 bg-white border-none"> <textarea id="emojionearea1">Default :smile:</textarea> 
  • Where is php ? I see only js and html . - Klimenkomud
  • If you swear precisely on this line, you can try this option: $(document).ready(function($) { - Regent
  • insert at the beginning of the handler ready - console.log($); - Igor
  • The same mistake. - xYaroslavGTx
  • @xYaroslavGTx and you are sure then that the error is not on the line with document.ready ? - Regent

2 answers 2

To avoid a conflict with $ , you can use this option:

 jQuery(document).ready(function($) { //использованиС jQuery как $ } 

The jQuery object is passed to the function called during document.ready as the first parameter. Since the parameter can be set to any name, $ is quite suitable for this. And since this is a local variable (parameter), when using $ inside a function, it will be taken, and not the global variable $ (which somewhere in the code was replaced with jQuery with something else).


Similarly, for the "short" version of document.ready :

 jQuery(function($) { //использованиС jQuery как $ }); 

When used outside of document.ready :

 (function($) { //использованиС jQuery как $ })(jQuery); 
     jQuery(document).ready(function($) { });