Simple jQuery JavaScript not working

This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!

Status: resolved
  • This topic has 7 replies, 2 voices, and was last updated 1 y, 2 mo by  Jacob.
Viewing 7 reply threads
  • Author
    Posts
    • #16446

      rfischmann
      Member

      Hi,

      I need this simple jQuery JavaScript to work:

      $(window).scroll(function(){
        if ($(this).scrollTop > 147) {
          $(".after-header-ads").addClass("fix-search");
        } else {
          $(".after-header-ads").removeClass("fix-search");
        }
      });

      But it’s not working, and I’ve already called jQuery in the header.

      What’s wrong with it?

      Cheers.

    • #16456

      Jacob
      Staff

      Hey there, You must be logged in to view this reply!

      Login | Register | Forgot Password?

    • #16471

      rfischmann
      Member

      Thanks Jacob, but it’s still not working for me.

      Here’s the last version of the code:

      jQuery(document).ready(function( $ ) {
          $(".after-header-ads").on("scroll", function(e) {
            if (this.scrollTop > 147) {
              $(".after-header-ads").addClass("fix-search");
            } else {
              $(".after-header-ads").removeClass("fix-search");
            }
          });
      });
    • #16480

      Jacob
      Staff

      Hey there, You must be logged in to view this reply!

      Login | Register | Forgot Password?

    • #16482

      rfischmann
      Member

      It’s in a scripts.js file together with other JavaScript code from my theme, that’s not the issue.

      Does it work on your side?

    • #16485

      Jacob
      Staff

      Hey there, You must be logged in to view this reply!

      Login | Register | Forgot Password?

    • #16490

      rfischmann
      Member

      Sorry for all the disturbance, I was missing () next to scrollTop. That was it. 😉

    • #16494

      Jacob
      Staff

      Hey there, You must be logged in to view this reply!

      Login | Register | Forgot Password?

Viewing 7 reply threads
  • You must be logged in to reply to this topic.

This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!

© Copyright 2020 by wpthms.com. All Rights Reserved.