How to add Jquery in Magento? Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?running jquery with no conflict inside CMS pagesIncluding Jquery in magento conflict the prototype.jsjQuery optimized load for module, using only one file (layout)Edit jQuery to Change Color of MenuMagento admin form date widget week number differs from jquery UI week numberCustom jQuery dont workMultiple Jquery Version for extension reasonAdd jQuery plugin without for whole site without a module (Magento 2)Adding jQuery doesn't seem to do anythingMagento2 add custom jquery pluginjQuery conflict in owlcarouselusing jQuery-ui accordion in checkout pageAdding Jquery to block (Still a nooblet)
Take 2! Is this homebrew Lady of Pain warlock patron balanced?
Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?
Why is it faster to reheat something than it is to cook it?
Why is Nikon 1.4g better when Nikon 1.8g is sharper?
How does the math work when buying airline miles?
Dating a Former Employee
How to play a character with a disability or mental disorder without being offensive?
Chinese Seal on silk painting - what does it mean?
Why do we bend a book to keep it straight?
Is there hard evidence that the grant peer review system performs significantly better than random?
What are the out-of-universe reasons for the references to Toby Maguire-era Spider-Man in Into the Spider-Verse?
Morning, Afternoon, Night Kanji
Did Deadpool rescue all of the X-Force?
Trademark violation for app?
Generate an RGB colour grid
Is it fair for a professor to grade us on the possession of past papers?
Drawing without replacement: why is the order of draw irrelevant?
Maximum summed subsequences with non-adjacent items
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
How do living politicians protect their readily obtainable signatures from misuse?
Is there any word for a place full of confusion?
Why wasn't DOSKEY integrated with COMMAND.COM?
What is the difference between globalisation and imperialism?
SF book about people trapped in a series of worlds they imagine
How to add Jquery in Magento?
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?running jquery with no conflict inside CMS pagesIncluding Jquery in magento conflict the prototype.jsjQuery optimized load for module, using only one file (layout)Edit jQuery to Change Color of MenuMagento admin form date widget week number differs from jquery UI week numberCustom jQuery dont workMultiple Jquery Version for extension reasonAdd jQuery plugin without for whole site without a module (Magento 2)Adding jQuery doesn't seem to do anythingMagento2 add custom jquery pluginjQuery conflict in owlcarouselusing jQuery-ui accordion in checkout pageAdding Jquery to block (Still a nooblet)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In my current project in about us page I need to add tabs to switch between different section I know this can be done by Jquery tabs but I don't know how to do this when integrating with magento.
magento-1.9 magento-1 jquery
add a comment |
In my current project in about us page I need to add tabs to switch between different section I know this can be done by Jquery tabs but I don't know how to do this when integrating with magento.
magento-1.9 magento-1 jquery
add a comment |
In my current project in about us page I need to add tabs to switch between different section I know this can be done by Jquery tabs but I don't know how to do this when integrating with magento.
magento-1.9 magento-1 jquery
In my current project in about us page I need to add tabs to switch between different section I know this can be done by Jquery tabs but I don't know how to do this when integrating with magento.
magento-1.9 magento-1 jquery
magento-1.9 magento-1 jquery
edited 2 days ago
7ochem
5,85493769
5,85493769
asked Nov 27 '14 at 7:00
don7don7
631314
631314
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Assuming you created a CMS Page already and name of that page is About Us
this name should be included in if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='your_page_name'):
Now add this code in your app/design/frontend/your_package/your_theme/template/page/html/head.phtml
<?php $headBlock = $this->getLayout()->getBlock('head');
if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='About Us'):
?>
<link rel="stylesheet"href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript"> jQuery(function() jQuery( "#tabs" ).tabs(); );</script>
<?php endif; ?>
Then open content section of your CMS Page.
<div style="float: right; width: 200px;">
<p>block type="tag/popular" template="tag/popular.phtml"</p>
</div>
<div id="tabs" style="width: 680px;">
<ul>
<li><a href="#tabs-1">You text here.</a></li>
<li><a href="#tabs-2">You text here.</a></li>
<li><a href="#tabs-3">You text here.</a></li>
</ul>
<div id="tabs-1">
<p>You text here.</p>
</div>
<div id="tabs-2">
<p>You text here.</p>
</div>
<div id="tabs-3">
<p>You text here.</p>
<p>You text here.</p>
</div>
</div>
paste this code and this will create jquery tabs in your frontend.Hope this helps.
here is a reference link if you have any doubts.
thankyou this worked
– don7
Nov 27 '14 at 7:11
3
Adding scripts and custom tags to the head.phtml file is against Magento's best practices. The new script tags should be added via layout xml and you can add custom update handles to the about us page to target that page specifically. The script tags should be broken out into it's own javacript file as well and imported via layout xml as well.
– Tyler Craft
Jan 21 '15 at 16:20
add a comment |
I wouldn't suggest to edit your head.phtml
template for this. Most of the times you don't need a custom head template in your own theme because the core one is already doing its job.
Also personally I don't like to write code that's based on exceptions (if A then do this, if B then do this). If you need a lot of different javascripts on a lot of different pages, then your head.phtml
would be filled with a lot of if statements.
I would suggest to add jQuery through layout XML. With CMS pages you have the ability to add extra layout XML in the admin when editing the page. Here you find an example setting a different template to the about us page. In the same way you can add jQuery to the about us page. Add this layout XML:
<reference name="head">
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.x.x.js</script>
</action>
<block type="core/text" name="jquery.noconflict">
<action method="setText">
<text><![CDATA[<script type="text/javascript">var $j = jQuery.noConflict();</script>]]>
</text>
</action>
</block>
</reference>
add a comment |
Or just simple copy to you theme dir, like skinfrontend[your theme]defaultjs
and add this to your theme's page.xml
:
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.9.1.min.js</script>
</action>
add a comment |
Okay I have found a way to make prototype, jQuery and bootstrap work without interfering with each other and without using jQuery.noConflict()
. My layout setup (page.xml
) was following(stripped for easier read):
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
</block>
I was getting errors like following:
TypeError: element.attachEvent is not a function
element.attachEvent("on" + actualEventName, responder);
TypeError: element.dispatchEvent is not a function
element.dispatchEvent(event);
I did not want to change $
everywhere. So, I made three javascript files as follows:
proto_to_temp.js having following code:
var $tempPrototypeDollar = $;
after_jquery.js having following code:
$ = jQuery;
after_all.js having following code:
$ = $tempPrototypeDollar;
As you can probably guess already, the first script assigns current $
variable (owned by prototype) to a temporary variable called $tempPrototypeDollar
. Second script simply assigns jQuery
to $
. Third script assigns the content of $tempPrototypeDollar
back to $
.
I included these three scripts in the following order:
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/proto_to_temp.js</script></action><!-- First Script goes just before jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_jquery.js</script></action><!-- Second Script goes just after jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_all.js</script></action><!-- Third Script goes after all jQuery related code has been included -->
</block>
This solved all the problems for me and now jquery, bootstrap and prototype, all seem to work fine.
add a comment |
Include the following in the top of the design page
<script>
var $j = jQuery.noConflict();
</script>
And use jQuery as $j
instead of $(Eg:$j('.class').hide();)
PS: You can use any other variable instead of j
in var $j
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f45569%2fhow-to-add-jquery-in-magento%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assuming you created a CMS Page already and name of that page is About Us
this name should be included in if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='your_page_name'):
Now add this code in your app/design/frontend/your_package/your_theme/template/page/html/head.phtml
<?php $headBlock = $this->getLayout()->getBlock('head');
if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='About Us'):
?>
<link rel="stylesheet"href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript"> jQuery(function() jQuery( "#tabs" ).tabs(); );</script>
<?php endif; ?>
Then open content section of your CMS Page.
<div style="float: right; width: 200px;">
<p>block type="tag/popular" template="tag/popular.phtml"</p>
</div>
<div id="tabs" style="width: 680px;">
<ul>
<li><a href="#tabs-1">You text here.</a></li>
<li><a href="#tabs-2">You text here.</a></li>
<li><a href="#tabs-3">You text here.</a></li>
</ul>
<div id="tabs-1">
<p>You text here.</p>
</div>
<div id="tabs-2">
<p>You text here.</p>
</div>
<div id="tabs-3">
<p>You text here.</p>
<p>You text here.</p>
</div>
</div>
paste this code and this will create jquery tabs in your frontend.Hope this helps.
here is a reference link if you have any doubts.
thankyou this worked
– don7
Nov 27 '14 at 7:11
3
Adding scripts and custom tags to the head.phtml file is against Magento's best practices. The new script tags should be added via layout xml and you can add custom update handles to the about us page to target that page specifically. The script tags should be broken out into it's own javacript file as well and imported via layout xml as well.
– Tyler Craft
Jan 21 '15 at 16:20
add a comment |
Assuming you created a CMS Page already and name of that page is About Us
this name should be included in if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='your_page_name'):
Now add this code in your app/design/frontend/your_package/your_theme/template/page/html/head.phtml
<?php $headBlock = $this->getLayout()->getBlock('head');
if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='About Us'):
?>
<link rel="stylesheet"href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript"> jQuery(function() jQuery( "#tabs" ).tabs(); );</script>
<?php endif; ?>
Then open content section of your CMS Page.
<div style="float: right; width: 200px;">
<p>block type="tag/popular" template="tag/popular.phtml"</p>
</div>
<div id="tabs" style="width: 680px;">
<ul>
<li><a href="#tabs-1">You text here.</a></li>
<li><a href="#tabs-2">You text here.</a></li>
<li><a href="#tabs-3">You text here.</a></li>
</ul>
<div id="tabs-1">
<p>You text here.</p>
</div>
<div id="tabs-2">
<p>You text here.</p>
</div>
<div id="tabs-3">
<p>You text here.</p>
<p>You text here.</p>
</div>
</div>
paste this code and this will create jquery tabs in your frontend.Hope this helps.
here is a reference link if you have any doubts.
thankyou this worked
– don7
Nov 27 '14 at 7:11
3
Adding scripts and custom tags to the head.phtml file is against Magento's best practices. The new script tags should be added via layout xml and you can add custom update handles to the about us page to target that page specifically. The script tags should be broken out into it's own javacript file as well and imported via layout xml as well.
– Tyler Craft
Jan 21 '15 at 16:20
add a comment |
Assuming you created a CMS Page already and name of that page is About Us
this name should be included in if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='your_page_name'):
Now add this code in your app/design/frontend/your_package/your_theme/template/page/html/head.phtml
<?php $headBlock = $this->getLayout()->getBlock('head');
if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='About Us'):
?>
<link rel="stylesheet"href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript"> jQuery(function() jQuery( "#tabs" ).tabs(); );</script>
<?php endif; ?>
Then open content section of your CMS Page.
<div style="float: right; width: 200px;">
<p>block type="tag/popular" template="tag/popular.phtml"</p>
</div>
<div id="tabs" style="width: 680px;">
<ul>
<li><a href="#tabs-1">You text here.</a></li>
<li><a href="#tabs-2">You text here.</a></li>
<li><a href="#tabs-3">You text here.</a></li>
</ul>
<div id="tabs-1">
<p>You text here.</p>
</div>
<div id="tabs-2">
<p>You text here.</p>
</div>
<div id="tabs-3">
<p>You text here.</p>
<p>You text here.</p>
</div>
</div>
paste this code and this will create jquery tabs in your frontend.Hope this helps.
here is a reference link if you have any doubts.
Assuming you created a CMS Page already and name of that page is About Us
this name should be included in if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='your_page_name'):
Now add this code in your app/design/frontend/your_package/your_theme/template/page/html/head.phtml
<?php $headBlock = $this->getLayout()->getBlock('head');
if ($headBlock->getModuleName() == 'Mage_Page' && $headBlock->getTitle() =='About Us'):
?>
<link rel="stylesheet"href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript"> jQuery(function() jQuery( "#tabs" ).tabs(); );</script>
<?php endif; ?>
Then open content section of your CMS Page.
<div style="float: right; width: 200px;">
<p>block type="tag/popular" template="tag/popular.phtml"</p>
</div>
<div id="tabs" style="width: 680px;">
<ul>
<li><a href="#tabs-1">You text here.</a></li>
<li><a href="#tabs-2">You text here.</a></li>
<li><a href="#tabs-3">You text here.</a></li>
</ul>
<div id="tabs-1">
<p>You text here.</p>
</div>
<div id="tabs-2">
<p>You text here.</p>
</div>
<div id="tabs-3">
<p>You text here.</p>
<p>You text here.</p>
</div>
</div>
paste this code and this will create jquery tabs in your frontend.Hope this helps.
here is a reference link if you have any doubts.
answered Nov 27 '14 at 7:05
dh47dh47
1,68611431
1,68611431
thankyou this worked
– don7
Nov 27 '14 at 7:11
3
Adding scripts and custom tags to the head.phtml file is against Magento's best practices. The new script tags should be added via layout xml and you can add custom update handles to the about us page to target that page specifically. The script tags should be broken out into it's own javacript file as well and imported via layout xml as well.
– Tyler Craft
Jan 21 '15 at 16:20
add a comment |
thankyou this worked
– don7
Nov 27 '14 at 7:11
3
Adding scripts and custom tags to the head.phtml file is against Magento's best practices. The new script tags should be added via layout xml and you can add custom update handles to the about us page to target that page specifically. The script tags should be broken out into it's own javacript file as well and imported via layout xml as well.
– Tyler Craft
Jan 21 '15 at 16:20
thankyou this worked
– don7
Nov 27 '14 at 7:11
thankyou this worked
– don7
Nov 27 '14 at 7:11
3
3
Adding scripts and custom tags to the head.phtml file is against Magento's best practices. The new script tags should be added via layout xml and you can add custom update handles to the about us page to target that page specifically. The script tags should be broken out into it's own javacript file as well and imported via layout xml as well.
– Tyler Craft
Jan 21 '15 at 16:20
Adding scripts and custom tags to the head.phtml file is against Magento's best practices. The new script tags should be added via layout xml and you can add custom update handles to the about us page to target that page specifically. The script tags should be broken out into it's own javacript file as well and imported via layout xml as well.
– Tyler Craft
Jan 21 '15 at 16:20
add a comment |
I wouldn't suggest to edit your head.phtml
template for this. Most of the times you don't need a custom head template in your own theme because the core one is already doing its job.
Also personally I don't like to write code that's based on exceptions (if A then do this, if B then do this). If you need a lot of different javascripts on a lot of different pages, then your head.phtml
would be filled with a lot of if statements.
I would suggest to add jQuery through layout XML. With CMS pages you have the ability to add extra layout XML in the admin when editing the page. Here you find an example setting a different template to the about us page. In the same way you can add jQuery to the about us page. Add this layout XML:
<reference name="head">
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.x.x.js</script>
</action>
<block type="core/text" name="jquery.noconflict">
<action method="setText">
<text><![CDATA[<script type="text/javascript">var $j = jQuery.noConflict();</script>]]>
</text>
</action>
</block>
</reference>
add a comment |
I wouldn't suggest to edit your head.phtml
template for this. Most of the times you don't need a custom head template in your own theme because the core one is already doing its job.
Also personally I don't like to write code that's based on exceptions (if A then do this, if B then do this). If you need a lot of different javascripts on a lot of different pages, then your head.phtml
would be filled with a lot of if statements.
I would suggest to add jQuery through layout XML. With CMS pages you have the ability to add extra layout XML in the admin when editing the page. Here you find an example setting a different template to the about us page. In the same way you can add jQuery to the about us page. Add this layout XML:
<reference name="head">
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.x.x.js</script>
</action>
<block type="core/text" name="jquery.noconflict">
<action method="setText">
<text><![CDATA[<script type="text/javascript">var $j = jQuery.noConflict();</script>]]>
</text>
</action>
</block>
</reference>
add a comment |
I wouldn't suggest to edit your head.phtml
template for this. Most of the times you don't need a custom head template in your own theme because the core one is already doing its job.
Also personally I don't like to write code that's based on exceptions (if A then do this, if B then do this). If you need a lot of different javascripts on a lot of different pages, then your head.phtml
would be filled with a lot of if statements.
I would suggest to add jQuery through layout XML. With CMS pages you have the ability to add extra layout XML in the admin when editing the page. Here you find an example setting a different template to the about us page. In the same way you can add jQuery to the about us page. Add this layout XML:
<reference name="head">
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.x.x.js</script>
</action>
<block type="core/text" name="jquery.noconflict">
<action method="setText">
<text><![CDATA[<script type="text/javascript">var $j = jQuery.noConflict();</script>]]>
</text>
</action>
</block>
</reference>
I wouldn't suggest to edit your head.phtml
template for this. Most of the times you don't need a custom head template in your own theme because the core one is already doing its job.
Also personally I don't like to write code that's based on exceptions (if A then do this, if B then do this). If you need a lot of different javascripts on a lot of different pages, then your head.phtml
would be filled with a lot of if statements.
I would suggest to add jQuery through layout XML. With CMS pages you have the ability to add extra layout XML in the admin when editing the page. Here you find an example setting a different template to the about us page. In the same way you can add jQuery to the about us page. Add this layout XML:
<reference name="head">
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.x.x.js</script>
</action>
<block type="core/text" name="jquery.noconflict">
<action method="setText">
<text><![CDATA[<script type="text/javascript">var $j = jQuery.noConflict();</script>]]>
</text>
</action>
</block>
</reference>
answered Jan 30 '15 at 10:34
7ochem7ochem
5,85493769
5,85493769
add a comment |
add a comment |
Or just simple copy to you theme dir, like skinfrontend[your theme]defaultjs
and add this to your theme's page.xml
:
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.9.1.min.js</script>
</action>
add a comment |
Or just simple copy to you theme dir, like skinfrontend[your theme]defaultjs
and add this to your theme's page.xml
:
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.9.1.min.js</script>
</action>
add a comment |
Or just simple copy to you theme dir, like skinfrontend[your theme]defaultjs
and add this to your theme's page.xml
:
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.9.1.min.js</script>
</action>
Or just simple copy to you theme dir, like skinfrontend[your theme]defaultjs
and add this to your theme's page.xml
:
<action method="addItem">
<type>skin_js</type>
<script>js/jquery-1.9.1.min.js</script>
</action>
edited Sep 30 '15 at 9:52
7ochem
5,85493769
5,85493769
answered Jan 21 '15 at 16:13
user956584user956584
1416
1416
add a comment |
add a comment |
Okay I have found a way to make prototype, jQuery and bootstrap work without interfering with each other and without using jQuery.noConflict()
. My layout setup (page.xml
) was following(stripped for easier read):
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
</block>
I was getting errors like following:
TypeError: element.attachEvent is not a function
element.attachEvent("on" + actualEventName, responder);
TypeError: element.dispatchEvent is not a function
element.dispatchEvent(event);
I did not want to change $
everywhere. So, I made three javascript files as follows:
proto_to_temp.js having following code:
var $tempPrototypeDollar = $;
after_jquery.js having following code:
$ = jQuery;
after_all.js having following code:
$ = $tempPrototypeDollar;
As you can probably guess already, the first script assigns current $
variable (owned by prototype) to a temporary variable called $tempPrototypeDollar
. Second script simply assigns jQuery
to $
. Third script assigns the content of $tempPrototypeDollar
back to $
.
I included these three scripts in the following order:
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/proto_to_temp.js</script></action><!-- First Script goes just before jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_jquery.js</script></action><!-- Second Script goes just after jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_all.js</script></action><!-- Third Script goes after all jQuery related code has been included -->
</block>
This solved all the problems for me and now jquery, bootstrap and prototype, all seem to work fine.
add a comment |
Okay I have found a way to make prototype, jQuery and bootstrap work without interfering with each other and without using jQuery.noConflict()
. My layout setup (page.xml
) was following(stripped for easier read):
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
</block>
I was getting errors like following:
TypeError: element.attachEvent is not a function
element.attachEvent("on" + actualEventName, responder);
TypeError: element.dispatchEvent is not a function
element.dispatchEvent(event);
I did not want to change $
everywhere. So, I made three javascript files as follows:
proto_to_temp.js having following code:
var $tempPrototypeDollar = $;
after_jquery.js having following code:
$ = jQuery;
after_all.js having following code:
$ = $tempPrototypeDollar;
As you can probably guess already, the first script assigns current $
variable (owned by prototype) to a temporary variable called $tempPrototypeDollar
. Second script simply assigns jQuery
to $
. Third script assigns the content of $tempPrototypeDollar
back to $
.
I included these three scripts in the following order:
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/proto_to_temp.js</script></action><!-- First Script goes just before jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_jquery.js</script></action><!-- Second Script goes just after jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_all.js</script></action><!-- Third Script goes after all jQuery related code has been included -->
</block>
This solved all the problems for me and now jquery, bootstrap and prototype, all seem to work fine.
add a comment |
Okay I have found a way to make prototype, jQuery and bootstrap work without interfering with each other and without using jQuery.noConflict()
. My layout setup (page.xml
) was following(stripped for easier read):
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
</block>
I was getting errors like following:
TypeError: element.attachEvent is not a function
element.attachEvent("on" + actualEventName, responder);
TypeError: element.dispatchEvent is not a function
element.dispatchEvent(event);
I did not want to change $
everywhere. So, I made three javascript files as follows:
proto_to_temp.js having following code:
var $tempPrototypeDollar = $;
after_jquery.js having following code:
$ = jQuery;
after_all.js having following code:
$ = $tempPrototypeDollar;
As you can probably guess already, the first script assigns current $
variable (owned by prototype) to a temporary variable called $tempPrototypeDollar
. Second script simply assigns jQuery
to $
. Third script assigns the content of $tempPrototypeDollar
back to $
.
I included these three scripts in the following order:
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/proto_to_temp.js</script></action><!-- First Script goes just before jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_jquery.js</script></action><!-- Second Script goes just after jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_all.js</script></action><!-- Third Script goes after all jQuery related code has been included -->
</block>
This solved all the problems for me and now jquery, bootstrap and prototype, all seem to work fine.
Okay I have found a way to make prototype, jQuery and bootstrap work without interfering with each other and without using jQuery.noConflict()
. My layout setup (page.xml
) was following(stripped for easier read):
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
</block>
I was getting errors like following:
TypeError: element.attachEvent is not a function
element.attachEvent("on" + actualEventName, responder);
TypeError: element.dispatchEvent is not a function
element.dispatchEvent(event);
I did not want to change $
everywhere. So, I made three javascript files as follows:
proto_to_temp.js having following code:
var $tempPrototypeDollar = $;
after_jquery.js having following code:
$ = jQuery;
after_all.js having following code:
$ = $tempPrototypeDollar;
As you can probably guess already, the first script assigns current $
variable (owned by prototype) to a temporary variable called $tempPrototypeDollar
. Second script simply assigns jQuery
to $
. Third script assigns the content of $tempPrototypeDollar
back to $
.
I included these three scripts in the following order:
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>varien/menu.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/proto_to_temp.js</script></action><!-- First Script goes just before jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/jquery.min.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_jquery.js</script></action><!-- Second Script goes just after jQuery include-->
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/bootstrap.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/responsive-tabs.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/clickable.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addJs"><script>buzzthemes/buzz-intro/bootstrap/site.js</script></action>
<action method="addJs"><script>buzzthemes/buzz-intro/conflict/after_all.js</script></action><!-- Third Script goes after all jQuery related code has been included -->
</block>
This solved all the problems for me and now jquery, bootstrap and prototype, all seem to work fine.
answered Mar 18 '16 at 13:11
SugatoSugato
8514
8514
add a comment |
add a comment |
Include the following in the top of the design page
<script>
var $j = jQuery.noConflict();
</script>
And use jQuery as $j
instead of $(Eg:$j('.class').hide();)
PS: You can use any other variable instead of j
in var $j
add a comment |
Include the following in the top of the design page
<script>
var $j = jQuery.noConflict();
</script>
And use jQuery as $j
instead of $(Eg:$j('.class').hide();)
PS: You can use any other variable instead of j
in var $j
add a comment |
Include the following in the top of the design page
<script>
var $j = jQuery.noConflict();
</script>
And use jQuery as $j
instead of $(Eg:$j('.class').hide();)
PS: You can use any other variable instead of j
in var $j
Include the following in the top of the design page
<script>
var $j = jQuery.noConflict();
</script>
And use jQuery as $j
instead of $(Eg:$j('.class').hide();)
PS: You can use any other variable instead of j
in var $j
edited 2 days ago
7ochem
5,85493769
5,85493769
answered Dec 24 '16 at 7:09
Jithin U. AhmedJithin U. Ahmed
1668
1668
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f45569%2fhow-to-add-jquery-in-magento%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown