2

I'm having some problems with jQuery after the 3.4.5 upgrade from 3.2.2.

$ is not defined.

I've done some trouble shooting, and found this: https://stackoverflow.com/questions/17687619/is-there-a-way-turn-off-jquery-noconflict-mode-in-wordpress

but if I run:

$ = jQuery.noConflict(true); then the new issue is that jQuery is not defined.

This isn't an issue in my 3.2.2 site, where both $ and jQuery are defined.

I've tried things such as setting jQuery = $ after the noConflict statement and cloning jQuery into $ but neither of those worked.

I'm running jQuery 1.8.3 instead of the jQuery included with Joomla. I also made sure mootools wasn't beeing included.

Is there a way to get $ and jQuery to work at the same time?

  • Did you try "(function($){}(jquery);" suggested in comments in the question you linked? – Ville Niemi Nov 6 '15 at 17:00
1

Firstly, there's no reason why you should be using jQuery 1.8.3 as it's an old and unsupported version. Please stick with what Joomla provides (1.11.3).

The template and ALL extensions you're using should be doing the following to import jQuery:

JHtml::_('jquery.framework');

Doing so ensures that it's only imported once when the head is being compiled. It means NoConflict mode is enabled, therefore the following is added below

jQuery.noConflict();

All templates/extensions should then always write their custom JS script like so:

jQuery(document).ready(function(){  
    var element = jQuery('#element');
});

or:

jQuery(document).ready(function($){  
    var element = $('#element');
});

In the second example, you can see that I have passed $ through as an alias of jQuery.

So overall, either your template or extension developer has not followed this process, therefore you can either find the culprit and fix it, or installed the jQuery Easy plugin.

Hope this helps

  • The template I'm using is including 1.8.3. I'm not sure that it can be easily upgraded – ContextSwitch Nov 6 '15 at 17:14
  • @ContextSwitch, if the template developer has not an update for their template, you could go and modify the line of code that makes jQuery available for your template. If they link to their own local version of jQuery, remove it and just use the recommended methods from Joomla or those provided by Lodder. These will be a few lines changes that will fix your issues, and you can easily revert after a future template update. – FFrewin Nov 6 '15 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.