FreiChat related discussions
How to fix jQuery conflict?

Hi,

I would like to integrate FreiChat into my system, but have the following problem when adding js file to the page:

TypeError: $ is not a function
$('body').on('click', function(e) {

My page structure is like this:

<script src="js/jquery.min.js"></script> ( version 1.9.0 )
<script>
$( document ).ready( function () {
// my custom code
});
</script><script src="apps/freichat/client/main.php?id=null&amp;xhash=&lt;?php%20echo%20freichatx_get_hash();%20?&gt;"></script>

Thank you for you help!

P. S. I have seen related discussions in other threads, but there were to explanation about cause of that problem.

Hi, I would like to integrate FreiChat into my system, but have the following problem when adding js file to the page: TypeError: $ is not a function $(&#039;body&#039;).on(&#039;click&#039;, function(e) { My page structure is like this: &amp;lt;script src=&quot;js/jquery.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt; ( version 1.9.0 ) &amp;lt;script&amp;gt; $( document ).ready( function () { // my custom code }); &amp;lt;/script&amp;gt; &amp;lt;script src=&quot;apps/freichat/client/main.php?id=null&amp;xhash=&amp;lt;?php echo freichatx_get_hash(); ?&amp;gt;&quot;&amp;gt;&amp;lt;/script&amp;gt; Thank you for you help! P. S. I have seen related discussions in other threads, but there were to explanation about cause of that problem.

It is an issue caused due to jQuery conflict.

Replace the '$' variable with 'jQuery' .

Or encapsulate it with an anonymous function passing jQuery as the parameter , like this:


(function($) {

$('body').on('click', function(e) {

$( document ).ready( function () {
// my custom code
});

}(jQuery);

It is an issue caused due to jQuery conflict. Replace the &#039;$&#039; variable with &#039;jQuery&#039; . Or encapsulate it with an anonymous function passing jQuery as the parameter , like this: &amp;lt;code&amp;gt; (function($) { $(&#039;body&#039;).on(&#039;click&#039;, function(e) { $( document ).ready( function () { // my custom code }); }(jQuery); &amp;lt;/code&amp;gt;
Necessity is the mother of all inventions!
240
2
0
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft