Magento 1.7 JavaScript – Fix Undefined jQuery Issue

javascriptjquerymagento-1.7magento-1.8prototype-js

I've added jquery 1.8.2 to both my page.xml file and the corresponding directory.. however i am still getting multiple Uncaught ReferenceError: jQuery is not defined errors.

Jquery no conflict has been added.

In the page.xml file the script src is

<action method="addJs"><script>jquery-1.8.2.min.js</script></action>

and it is the first script.

    <block type="page/html_head" name="head" as="head">

<action method="addJs"><script>jquery-1.8.2.min.js</script></action>

        <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>

ect.

Best Answer

Create a new .js file for eg. no-conflict.js and add the following content on it:

var $j = jQuery.noConflict();

And include your no-conflict.js just after your

<action method="addJs"><script>jquery-1.8.2.min.js</script></action> like this:

<action method="addJs"><script>no-conflict.js</script></action>

Then write your jQuery like this:

$j(document).ready(function(){
// write your code here
});

P.S. for more information on solving jquery conflict refer http://magento-online-tutorials.blogspot.in/2015/10/how-to-solve-jquery-and-prototype.html

Related Topic