JQuery and Joomla

General questions relating to Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Post Reply
LikeStuff
Joomla! Guru
Joomla! Guru
Posts: 790
Joined: Mon Jul 24, 2006 2:06 am

JQuery and Joomla

Post by LikeStuff » Mon May 13, 2019 3:56 pm

Can you please explain how jQuery works with Joomla? I'm a bit confused and here's why.

I thought that jQuery was automatically installed with Joomla because some things that requires jQuery worked but some things did not. For example, I have a "back to top" code that requires jquery and it worked fine, but then I wanted to use the jQuery date selector below but it did not work unless I add the jQuery link below in my template. I had also installed the "jQuery Easy" plugin, made my selections and published it but it still didn't work.

<script src="https://code.jquery.com/jq ... ></script>

Code: Select all

// highlight current day
$(document).ready(function() {
  $('#business-hours li').eq(new Date().getDay()).addClass('today');
});
Thanks in advance!!

User avatar
paulala
Joomla! Explorer
Joomla! Explorer
Posts: 301
Joined: Sat Oct 30, 2010 12:32 pm
Location: Scotland
Contact:

Re: JQuery and Joomla

Post by paulala » Mon May 13, 2019 6:23 pm

Some templates come with jQuery baked in.

Also be aware that some templates do not support the $ method of calling jQuery and it must be called explicitly.

Is it gantry youre using?

Try calling it like this...

Code: Select all

// highlight current day
jQuery(document).ready(function() {
  jQuery('#business-hours li').eq(new Date().getDay()).addClass('today');
});
Also sometimes it loads on certain pages but not on others if its not been specifically enabled for that page(outline)
Warm Regards,
Paula Livingstone, Skydiving Instructor and Network Security Consultant
https://paulalivingstone.com
http://rustyice.co.uk

LikeStuff
Joomla! Guru
Joomla! Guru
Posts: 790
Joined: Mon Jul 24, 2006 2:06 am

Re: JQuery and Joomla

Post by LikeStuff » Fri May 17, 2019 9:48 pm

This worked. Thank you very much.

Code: Select all

// highlight current day
jQuery(document).ready(function() {
  jQuery('#business-hours li').eq(new Date().getDay()).addClass('today');
});

User avatar
paulala
Joomla! Explorer
Joomla! Explorer
Posts: 301
Joined: Sat Oct 30, 2010 12:32 pm
Location: Scotland
Contact:

Re: JQuery and Joomla

Post by paulala » Sat May 18, 2019 7:23 am

LikeStuff wrote:
Fri May 17, 2019 9:48 pm
This worked. Thank you very much.

Code: Select all

// highlight current day
jQuery(document).ready(function() {
  jQuery('#business-hours li').eq(new Date().getDay()).addClass('today');
});
Ah thats good. Ive never really seen an explicit explanation of the reasons why the $ doesn't work in Joomla but I suspect its closely related to compatibility mode and the connection to mootools.

This link is interesting:

http://learn.jquery.com/using-jquery-co ... libraries/
Warm Regards,
Paula Livingstone, Skydiving Instructor and Network Security Consultant
https://paulalivingstone.com
http://rustyice.co.uk

LikeStuff
Joomla! Guru
Joomla! Guru
Posts: 790
Joined: Mon Jul 24, 2006 2:06 am

Re: JQuery and Joomla

Post by LikeStuff » Thu Jun 13, 2019 5:56 pm

Hi there,

Is there a way that I can use the script with $ in my template, instead of jQuery in front of it - because I don't know how to edit javascript and I'm getting stuck all the time.

So is there something that I can add to my template so that the script will work without having to replace $ with this jQuery.

Code: Select all

$('#countdown').countdown({
date: '12/24/2020 23:59:59'
}, function () {
  alert('Registration Closed!');
});
Thank you!

User avatar
pmleconte
Joomla! Explorer
Joomla! Explorer
Posts: 390
Joined: Fri Mar 17, 2017 12:55 pm
Location: France

Re: JQuery and Joomla

Post by pmleconte » Thu Jun 13, 2019 6:51 pm

Hi,

Please check jquery.noconflict documentation https://api.jquery.com/jQuery.noConflict/

Pascal
If anything can go wrong, it will.
https://www.conseilgouz.com/en

LikeStuff
Joomla! Guru
Joomla! Guru
Posts: 790
Joined: Mon Jul 24, 2006 2:06 am

Re: JQuery and Joomla

Post by LikeStuff » Thu Jun 13, 2019 7:21 pm

I actually did look at that and tried a few things before posting here but they didn't work. As I said I don't know javascript so I'm just basically guessing.

Thanks!

User avatar
paulala
Joomla! Explorer
Joomla! Explorer
Posts: 301
Joined: Sat Oct 30, 2010 12:32 pm
Location: Scotland
Contact:

Re: JQuery and Joomla

Post by paulala » Fri Jun 14, 2019 10:17 am

Assuming the scripts aren't too complicated you could just step through them in a text editor and replace all occurrences of '$' with 'jQuery'

Try it. Its an easy win if it works.

If it doesn't then it may be that you have some other occurrences of '$' in your script that isn't representing jQuery. Then it gets a bit more complex.
Warm Regards,
Paula Livingstone, Skydiving Instructor and Network Security Consultant
https://paulalivingstone.com
http://rustyice.co.uk

LikeStuff
Joomla! Guru
Joomla! Guru
Posts: 790
Joined: Mon Jul 24, 2006 2:06 am

Re: JQuery and Joomla

Post by LikeStuff » Fri Jun 14, 2019 1:33 pm

Code: Select all

jQuery('#countdown').countdown({
 date: '12/24/2020 23:59:59'
 }, function () {
   alert('Registration Closed!');
});
I replaced the '$' with 'jQuery' in the code above but it's still not working. If the code above looks good, could it be something else that's not working?

Thanks!

jonBuckner1
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Nov 12, 2012 9:08 am

Re: JQuery and Joomla

Post by jonBuckner1 » Fri Jun 14, 2019 11:05 pm

I have no assistance to offer, but might be helpful to others to know your setup ie
joomla version, template, extensions etc

harperlala
Joomla! Guru
Joomla! Guru
Posts: 573
Joined: Mon Aug 24, 2015 5:55 pm

Re: JQuery and Joomla

Post by harperlala » Sun Jun 16, 2019 4:50 pm

@jon: you should use f12 browser and see bug in console tab, then post error here....

User avatar
paulala
Joomla! Explorer
Joomla! Explorer
Posts: 301
Joined: Sat Oct 30, 2010 12:32 pm
Location: Scotland
Contact:

Re: JQuery and Joomla

Post by paulala » Thu Jul 11, 2019 10:26 am

Does the script work outside of Joomla?
Warm Regards,
Paula Livingstone, Skydiving Instructor and Network Security Consultant
https://paulalivingstone.com
http://rustyice.co.uk


Post Reply

Return to “General Questions/New to Joomla! 3.x”