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 ?
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.
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>
Using PHP you can add jQuery as below. Find more info here .
<?php
$document = JFactory::getDocument();
$document->addScript('/path/to_the/js/jquery.js');
?>
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');
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.