Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:35:13+00:00 2026-06-17T10:35:13+00:00

I am trying to simply add the class active on window scroll and remove

  • 0

I am trying to simply add the class active on window scroll and remove it when not scrolled.

I tried to follow these directions located here:
jQuery : add css class to menu item based on browser scroller position

However, I still must be doing something wrong. Nothing is happening to the id myCart when scrolling.

I have the following html:

<div id="myCart" class="active">
<div class="add-to-cart">
<div class="clearfix qty_ticker">
<label for="qty">Qty:</label>
<span class="marker_qty_left"> </span>
<input id="qty" class="input-text qty" type="text" title="Qty" value="1" maxlength="12" name="qty">
<span class="marker_qty_right"> </span>
</div>
<button class="button btn-cart" onclick="productAddToCartForm.submit(this)" title="Add to Cart" type="button">
<span>
<span>Add to Cart</span>
</span>
</button>
</div>
</div>

And the following javascript or jquery:

<script type="text/javascript">
$(window).scroll(function() {    
    // find the id with class 'active' and remove it
    $("#myCart").removeClass("active");
    // get the amount the window has scrolled
    var scroll = $(window).scrollTop();
    // add the 'active' class to the correct id based on the scroll amount
    if (scroll <= 500) {
        $("#myCart").addClass("active");
    }
});
</script>

Any help would be great!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:35:14+00:00Added an answer on June 17, 2026 at 10:35 am

    You are missing “)” at the end of your script which is causing the javascript not to compile.

    Code should be

    <script type="text/javascript">
    $(window).scroll(function() {    
        // find the id with class 'active' and remove it
        $("#myCart").removeClass("active");
        // get the amount the window has scrolled
        var scroll = $(window).scrollTop();
        // add the 'active' class to the correct id based on the scroll amount
        if (scroll <= 500) {
            $("#myCart").addClass("active");
        }
    });
    </script>
    

    When you are using both jquery and prototype, the jquery’s $ global variable conflicts with prototypes $ global variable. One way to fix that is to use jquery’s jQuery variable as such

      <script type="text/javascript">
    var $$ = jQuery;
    $$(window).scroll(function() {    
        // find the id with class 'active' and remove it
        $$("#myCart").removeClass("active");
        // get the amount the window has scrolled
        var scroll = $$(window).scrollTop();
        // add the 'active' class to the correct id based on the scroll amount
        if (scroll <= 500) {
            $$("#myCart").addClass("active");
        }
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to simply add objects to a mutable array but they WILL NOT
I am trying to simply add a Google Search bar onto my own map
I'm trying to create a simple Add-On for SQL Server 2008; it is simply
This will probably be an extremely simple question. I'm simply trying to remove duplicate
I simply am trying to add a color to the select item background within
I'm simply trying to add a bulleted list in an ASP.NET aspx page. I
I'm simply trying to add a JLabel to an existing JPanel. This seems really
... I am trying to dynamically add or remove classes to my ASP controls
I'm trying to add simple login page to ASP.NET MVC app. I actually use
I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.