Using JQuery to Calculate Scroll Error Percentage

I'm a beginner in JQuery and I need help with an error message that says:

Microsoft JScript runtime Error:'$'is Undefined

Learn more here

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="Scripts/jquery.min.js"></script>
<script type="text/javascript">        
    $(window).scroll(function () {
        var startValue = 70; // scrollTop value when to start incrementing
        var stopValue = 300; // scrollTop value when to stop incrementing
        var scrollTop = $(window).scrollTop();
        if (scrollTop > startValue && scrollTop <= stopValue)
            $("#pct").text((((scrollTop - startValue) / (stopValue - startValue)) * 100).toFixed(0));
        else if (scrollTop <= startValue)
            $("#pct").text(0);
        else if (scrollTop >= stopValue)
            $("#pct").text(100);
    });
</script>
 <style type="text/css">
     body {
        height:2000px;
      }

     #pct {
         height:150px;
         width:150px;
         background-color:#369;
         font:bold 60px verdana;
         padding:20px;
         position:absolute;
         top:400px;
         left:200px;
    }
  </style>
  </head>
 <body>
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> 
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 hi
 <div id="pct">0</div>
</body>
</html>

View on jsFiddle It works perfectly on jsFiddle, but not on Internet Explorer. Is something missing? Please assist. Thanks!

Answer №1

It seems that you may have overlooked including the following line:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

Answer №2

Ensure you are using the most up-to-date version of jQuery.

Check out this link for reference

$(window).scroll(function() {
    var scrollTop = $(window).scrollTop();
    if (scrollTop > 70 && scrollTop <= 300)
        $("#pct").text((((scrollTop-70)/(300-70))*100).toFixed(0));
    else if (scrollTop <= 70)
        $("#pct").text(0);
    else if (scrollTop >= 300)
        $("#pct").text(100);
});

Answer №3

It's essential to always include the jQuery library first before making any calls to it. Even if those calls are scattered throughout different scripts, ensure that references to them come after the jQuery inclusion.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Position one div on top of another div with no gaps between them

I want to position a div element so that the bottom half overlaps another div element. You can view a basic layout here When the transform property is enabled for .overlay, the element is moved halfway down but it also shows the white space of the parent ...

What is the method to verify if an AJAX request has already been initiated using Jquery?

Currently, I have implemented an Ajax request using Jquery to submit a form. $.ajax( { type: "POST", url: "login.php", data: $("#signin").serialize(), dataType: "json", cache: false, ...

Icon should be wrapped on two lines using the :before pseudo CSS element

My current scenario requires me to dynamically set the inner HTML of an element because it utilizes markdown: <div className='quote-copy' dangerouslySetInnerHTML={{ __html: body?.childMarkdownRemark?.html, }} /> Within t ...

Tips for concealing Vimeo URL on browser's inspect element

I've been attempting to conceal the Vimeo video URL from the browser, but it doesn't seem to be working correctly. I'm utilizing the Jplayer plugin to play a Vimeo video, and while it functions properly, the video links are still visible in ...

Adjust the height of an element using percentages

Over at this JSFiddle link, they demonstrated splitting a page into 3 parts. However, when I adjust the width of #wrapper to 100%, everything works perfectly. So why does changing height:400px to height:100% cause it to fail? #wrapper { width: 400px; ...

The RSS feed reader is currently malfunctioning

I'm having trouble loading an RSS feed from the following URL: http://solutions.astrology.com/scripts/it.dll?cust_id=aamfha&doc=daily07short/dailyshort.xml Here is the code I am using to try to read it: url = 'http://solutions.astrology.co ...

Utilizing JQuery UI to transmit POST data to a Django server

I have been utilizing the JQUERY UI documentation as a guide to develop a dialog form. In my form, I have specified method=POST and action= "{% url 'example:new_article' %}", so I assumed that clicking on the "Add Article' button would trigg ...

Looking to determine if a specific element is assigned multiple class names

Help needed! Can you tell me how to check if an element contains more than one classname using pure javascript, without using jQuery? For example: If #test has both the classnames "classA and classB", then { alert(true) } else { alert(false) } Here is ...

Is it possible to set a foreign key in Django as read-only and still successfully submit the form without encountering any errors?

I have been attempting to set a foreign key as read-only in my Django forms. I am developing a web application with system management capabilities and I need to prevent specific users from altering a certain field after it has been submitted. class Approv ...

What is the process of transforming a PSD file into a responsive HTML file?

I have a PSD file with multiple images that I need to display on my responsive website. The challenge is that when the images are displayed inside the webpage, their position needs to be set to absolute in order to maintain layout integrity. However, when ...

Resetting form fields in ASP.net using jquery

I recently implemented a jQuery datepicker on one of my pages and everything was functioning perfectly. However, I encountered an issue where upon refreshing the screen after clicking a button, the selected date would revert back to its original value or b ...

Steps to trigger a modal (bootstrap 5) in react upon clicking a cell within the Full Calendar interface

My goal is to trigger a modal window using Bootstrap 5 (not React-Bootstrap library) when clicking on a day in the FullCalendar Component in React. I attempted to access the modal by using jQuery's $, but encountered the error message "$ is not a fun ...

Can one efficiently retrieve all records from table 1 alongside corresponding metadata from table 2 within the same query?

In the process of developing a compact CRM system, I am wondering if there is a more efficient approach to fetching all entries from table 1 while also retrieving each entry's metadata from table 2, labeled as tasks t2. Currently, I am executing two ...

Pagination of data within the confines of a single page

Seeking assistance with implementing Django pagination for database rows while using Ajax and JQuery to stay on the same page. I have managed to display the first page of data successfully, but facing issues with navigating through the pages. I've inc ...

Looking to enhance current CSS3 organizational chart by adding a second primary level

I'm having difficulty trying to replicate the first-level (director) box with a vertical line in between. The original chart only has one level with subs below. Take a look at the image provided to see the desired outcome... You can find the CodePen ...

Controlling the first displayed page with JQuery Multi-Page functionality

Utilizing JQuery Mobile's multi-page approach, I am looking to optimize the order in which pages load. As a novice in JQuery and JavaScript, I am unsure how to go about this. I aim to verify the user's credentials through local storage upon init ...

modal dropdown with overflow in ui-select

Currently, I am encountering an issue with the display of a ui-select dropdown inside a ui bootstrap modal that has overflow css set up. Whenever the ui-select dropdown is opened, the list of options appears within the modal but is partially obscured by t ...

Encountered an error: Unable to access property 'tween' of an undefined variable in the Masterslider.js script

My webpage features three sliders using Master Slider alongside Fullpage.js. var slider = new MasterSlider(); slider.setup('masterslider', { width: 300, height: 300, });   slider.control('lightbox'); slider.control('slidei ...

The focus is not set on the textarea when the bootstrap modal is launched

http://jsfiddle.net/h3WDq/1921/ For some reason, I am unable to input text into a textarea when the modal is open. Even though the textarea is not within the modal and has a high z-index with absolute positioning. <textarea style='position:absol ...

When accessed through jQuery, the WebAPI Controller will route to a plain JSON view

I am encountering a strange issue with my ASP.NET MVC application. When calling a WebAPI controller through jQuery's $.get method, everything works fine until the callback function finishes. Instead of seeing my web page, I am redirected to a raw JSON ...