Javascript doesn't work when logged out

Hi, I added custom JS which works fine when logged in WP dashboard, but doesn’t work when logged out…

See here how it goes :

here’s the custom js code I found in other topics:

jQuery(function($){

	$(window).scroll(function(){

		if( $(this).scrollTop() == 0 ) {
			$('.x-navbar-fixed-top').removeClass('x-navbar-fixed-top');
		}

	});

});

jQuery(function($) {
 $(window).scroll(function() {
   if($('.x-navbar').hasClass('x-navbar-fixed-top')) {
     $('.x-navbar-fixed-top .x-brand img').attr('src','https://coupe-energetique-remi-portrait.ch/wp-content/uploads/2018/09/logo-ces-DEF-picto.png');
   }else{
     $('.x-navbar .x-brand img').attr('src','https://coupe-energetique-remi-portrait.ch/wp-content/uploads/2019/02/logo-ces-DEF.png');
   }
 });
});

Hi there,

Please try updating the code to:

(function($){

	$(window).scroll(function(){
		if( $(this).scrollTop() == 0 ) {
			$('.x-navbar-fixed-top').removeClass('x-navbar-fixed-top');
		}
	});

    $(window).scroll(function() {
       if($('.x-navbar').hasClass('x-navbar-fixed-top')) {
         $('.x-navbar-fixed-top .x-brand img').attr('src','https://coupe-energetique-remi-portrait.ch/wp-content/uploads/2018/09/logo-ces-DEF-picto.png');
       }else{
         $('.x-navbar .x-brand img').attr('src','https://coupe-energetique-remi-portrait.ch/wp-content/uploads/2019/02/logo-ces-DEF.png');
       }
   });

})(jQuery);

Let us know how it goes.

Thanks. It works fine now.

You’re welcome!
Thanks for letting us know that it has worked for you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.