0

I'm doing a laravel project with front-end in html/css/bootstrap.

I'm using Jquery 1.12.4 version

        (function($) {
            "use strict";
    
    function handlePreloader() {
            if($('.preloader').length){
                $('.preloader').delay(200).fadeOut(500);
            }
        }
            
        function headerStyle() {
                if($('.main-header').length){
                    var windowpos = $(window).scrollTop();
                    var siteHeader = $('.main-header');
                    var scrollLink = $('.scroll-to-top');
                    if (windowpos >= 200) {
                        siteHeader.addClass('fixed-header');
                        scrollLink.fadeIn(300);
                    } else {
                        siteHeader.removeClass('fixed-header');
                        scrollLink.fadeOut(300);
                    } 
        }
            }
            
            headerStyle();
        
        $(window).on('scroll', function() {
                headerStyle();
            });
            $(window).on('load', function() {
                handlePreloader();
            }); 
        
        })(window.jQuery);

6
  • Are you trying to run this before loading jQuery.js? Inspect what $ is inside your IIFE Commented Sep 12, 2020 at 12:52
  • No First JQuery and then Script file Commented Sep 12, 2020 at 13:14
  • So what did you see when inspect $? Commented Sep 12, 2020 at 13:18
  • I have also added lazy loading function handlePreloader() { if($('.preloader').length){ $('.preloader').delay(200).fadeOut(500); } } Commented Sep 12, 2020 at 13:29
  • please see the latest edit Commented Sep 12, 2020 at 13:32

1 Answer 1

1

to use $ symbol You must have made jQuery available to your script.

use below CDN it will import all jquery related things in the page

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

`

Sign up to request clarification or add additional context in comments.

5 Comments

JQuery is available in project folder at the right place and some of the other functions of Jquery are smoothly running.
what version of jquery you're using can you show us
I'm using Jquery 1.12.4 version
that is a too old one, change your jquery to a new one
I try to add JQuery CDN that you provide above but nothing work I'm getting the same error ..

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.