0

Everyone, I wanted to insert the Product collection in my Slider for this purpose I'm using JQuery script (In the theme Header) with the HTML and CSS. The Error is "$ signed undefined" while I'm doing inspect-->Console! The below example was trying to implement. kindly guide me! enter image description here

2

2 Answers 2

0

Jquery and js cannot be use directly in magento 2

so you have to do something like that

require(['jquery', 'jquery/ui'], function($){
  //all you jquery code here
});
1
  • <script type="text/javascript" xml="space">// <![CDATA[ require(['jquery'],function($){ $('.carousel[data-type="multi"] .item').each(function() { var next = $(this).next(); if (!next.length) { next = $(this).siblings(':first'); } next.children(':first-child').clone().appendTo($(this)); for (var i = 0; i &lt; 3; i++) { next = next.next(); if (!next.length) { next = $(this).siblings(':first'); } next.children(':first-child').clone().appendTo($(this)); } }); }); <script> // ]]></script>
    – Adeel Khan
    Commented Apr 8, 2020 at 5:39
0

You have to created one requirejs-config.js file inside your theme like,

var config = {
    map: {
        '*': {
            owlcarousel: 'Solwin_Module1/js/owl.carousel'
        }
    }
};

And then you need to include the js code inside require function like:

<script>
require(['jquery', 'owlcarousel'], function () {
    jQuery(document).ready(function () {
        jQuery("#owl-demo").owlCarousel({
        pagination : false
         });
    });
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.