0

I have seen many people struggle to including jQuery in their Joomla projects. I have seen this question pop-in up on SO many time. Even I have asked this question on SO while back. I thought of posting this, So that it will be helpful to you people.

How to include jQuery in Joomla ?

Community
  • 1
  • 1
Techie
  • 44,706
  • 42
  • 157
  • 243

1 Answers1

0

Method 1

Best and easiest way I found is(& the method I'm using without an issue) to install this extension. jQuery Easy. It's just not a extension, it will keep you out of conflicts.

http://extensions.joomla.org/extensions/core-enhancements/performance/jquery-scripts/18327

This plugin is meant to help clean and resolve front and back end issues when using instances of jQuery alongside the Mootools libraries.

Method 2

You can including it in your template as below

<script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/YOUR_TEMPLATE_NAME/PATH_TO_JAVASCRIPT_FOLDER/YOUR_JQUERY.js"></script>

Method 3

Using PHP you can add jQuery as below. Find more info here.

<?php
$document = JFactory::getDocument();
$document->addScript('/path/to_the/js/jquery.js');
?>

Method 4

This way it check whether jQuery version exists. if not add it.

<?php
  if(!JFactory::getApplication()->get('jquery')){
     JFactory::getApplication()->set('jquery',true);
     $doc = JFactory::getDocument();
     $document->addScript('/path/to_the/js/jquery.js');
  }
?>
Techie
  • 44,706
  • 42
  • 157
  • 243
  • You have a few errors on your example methods and also some of the methods in class JFactory do not exist in several versions of the platform. Example: `JFactory::getApplication()->get('jquery')`method get(). – McRui Jul 19 '13 at 13:06
  • it does. check the documentation rather than down voting answers without checking. – Techie Jul 19 '13 at 13:12