Unable to load JavaScript in an HTML file

I have tried numerous solutions for my issue, but none seem to work.

When testing in JSFiddle, the code works perfectly due to automatic onload support.

However, when I open the same HTML file locally in Chrome/IE/FireFox, the layout is correct but the JavaScript fails to execute.

I've verified my folder structure multiple times and it's all set up correctly.

The .js script is declared at the end of the HTML document just before the closing tag.

Oddly, an onclick function within the HTML opens a new window successfully, but the same function linking to the JS script doesn't work.

Just to mention, I'm using Sublime Text 2 for coding purposes.

Although the cursor changes when hovering over an icon on the webpage, indicating it's clickable, the image slider remains inactive.

Here is a snippet of the HTML:

<!doctype html>
<html>
  <head>
    <link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet'>
    <link href="warSupport.css" rel="stylesheet">
    <link href="warMain.css" rel="stylesheet">
  </head>

/ Section affected by JavaScript code /

<div class="slider-nav"> <a href="#" class="arrow-prev"><img src="./Images/Buttons/arrow-prev.png"></a>
    <ul class="slider-dots">
        <li class="dot active-dot">&bull;</li>
        <li class="dot">&bull;</li>
        <li class="dot">&bull;</li>
        <li class="dot">&bull;</li>
    </ul> <a href="#" class="arrow-next"><img src="./Images/Buttons/arrow-next.png"></a>
</div>

/ End of HTML Document /

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
    <script src="warCode.js"></script>
</body>

</html>

Javascript Code

var main = function () {

    $('.arrow-next').click(function () {
        var curSlide = $('.active-slide');
        var nexSlide = curSlide.next();
        var currentDot = $('.active-dot');
        var nextDot = currentDot.next();

        if (nexSlide.length == 0) {
            nexSlide = $('.slide').first();
        };

        if (nextDot.length == 0) {
            nextDot = $('.dot').first();
        }
        curSlide.fadeOut(600).removeClass('active-slide');
        nexSlide.fadeIn(600).addClass('active-slide');
        currentDot.removeClass('active-dot');
        nextDot.addClass('active-dot');
    });

    $('.arrow-prev').click(function () {
        var curSlide = $('.active-slide');
        var prevSlide = curSlide.prev();
        var currentDot = $('.active-dot');
        var prevDot = currentDot.prev();

        if (prevSlide.length == 0) {
            prevSlide = $('.slide').last();
        }

        if (prevDot.length == 0) {
            prevDot = $('.dot').last();
        }

        curSlide.fadeOut(500).removeClass('active-slide');
        prevSlide.fadeIn(500).addClass('active-slide');
        currentDot.removeClass('active-dot');
        prevDot.addClass('active-dot');


    });


};

$(document).ready(main);

CSS Code for Affected HTML Portion

/* Carousel */
 .slider {
    position: relative;
    width: 100%;
    height: 470px;
    border-bottom: 1px solid #ddd;
}
.slide {
    background: transparent url('http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/feature-gradient-transparent.png') center center no-repeat;
    background-size: cover;
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.active-slide {
    display: block;
}
.slide-copy h1 {
    color: #363636;
    font-family:'Oswald', sans-serif;
    font-weight: 400;
    font-size: 40px;
    margin-top: 105px;
    margin-bottom: 0px;
}
.slide-copy h2 {
    color: #b7b7b7;
    font-family:'Oswald', sans-serif;
    font-weight: 400;
    font-size: 40px;
    margin: 5px;
}
.slide-copy p {
    color: #959595;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.15em;
    line-height: 1.75em;
    margin-bottom: 15px;
    margin-top: 16px;
}
.slide-img {
    text-align: center;
}
/* Slide feature */
 .slide-feature {
    text-align: center;
    background-image: url('http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/ac.png');
    height: 470px;
}
.slide-feature img {
    margin-top: 112px;
    margin-bottom: 28px;
}
.slide-feature a {
    display: block;
    color: #6fc5e0;
    font-family:"HelveticaNeueMdCn", Helvetica, sans-serif;
    font-family:'Oswald', sans-serif;
    font-weight: 400;
    font-size: 20px;
}
.slider-nav {
    text-align: center;
    margin-top: 20px;
}
.arrow-prev {
    margin-right: 45px;
    display: inline-block;
    vertical-align: top;
    margin-top: 9px;
}
.arrow-next {
    margin-left: 45px;
    display: inline-block;
    vertical-align: top;
    margin-top: 9px;
}
.slider-dots {
    list-style: none;
    display: inline-block;
    padding-left: 0;
    margin-bottom: 0;
}
.slider-dots li {
    color: #bbbcbc;
    display: inline;
    font-size: 30px;
    margin-right: 5px;
}
.slider-dots li.active-dot {
    color: #363636;
}

Your assistance would be greatly appreciated.

Answer №1

It appears that jQuery is being imported twice from separate CDNs towards the bottom of your code. This redundancy could potentially be causing issues.

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

Setting the height of a div tag in CSS/HTML5 to match the current height of the browser window

Is there a way to make the height of my div tag always equal to the height of the browser's window, so it adjusts automatically when the browser is resized? I have tried using .class { height: 100%; } But this doesn't work. I've learne ...

Using SimplyJS and XML: extracting the value of a specific key

Hey there, I wanted to update you on my progress with the Pebble Watch project. I've switched over to using an official external API to make HTTP requests for values, and now I'm receiving results in XML format instead of JSON. Here's a ...

Creating valuable properties in TypeScript is a skill that requires knowledge and practice

In TypeScript, there is a unique feature available for defining properties with values using the `value` keyword. class Test { constructor(private value: number = 123) { } public MyValueProperty: number = 5; } Here is how you can define such ...

Terminate the ongoing PHP script execution

Is there a way to terminate the current PHP script? For instance: page.php <?php require('./other-page.php'); ?> <h4>this text is always displayed</h4> other-page.php <?php if($_GET['v'] == 'yes&ap ...

Is it possible to verify the existence of several arrays of data in a MongoDB database using Node.js?

I'm trying to verify if certain data exists in a database. If the data does exist, I want to set the value of k to 1. global.k = 0 let roll = {roll0:"1616",roll1:"234"} for (let i = 0; i < inputcount; i++) { let obj1 = roll["roll" + i]; const ...

Tips for ensuring an image fits perfectly within a MUI grid

I am currently working on an application that involves a collection of cards. My tech stack includes React and MUI v5. One issue I've been facing is with the grid layout, specifically in trying to keep the image size consistent within the grid item. ...

Learn how to dynamically disable unchecked checkboxes and apply specific CSS classes to checked checkboxes in Angular 12 with TypeScript

Currently, I am working on a project where I have successfully stored checkboxes dynamically using a JSON array of objects. However, I am facing an issue that requires your expertise. My goal is to allow the selection of only 5 checkboxes. Once this limit ...

Layering numerous backgrounds (Regular, Expanded, Regular) atop one another

After experiencing an issue with the background image not fitting the content properly at different resolutions, I attempted to divide the background into three parts and automatically stretch the middle section to fill the space between the top and bottom ...

How can you make nested JSON values optional in Joi Validation?

As I work on my API, I encounter a nested JSON structure that serves as the payload for the endpoint. Here is an example of what it looks like: {"item_id":"1245", "item_name":"asdffd", "item_Code":"1244", "attributes":[{"id":"it1","value":"1"},{"id":"it2" ...

An error occurs due to attempting to parse the data using JSON.parse

Trying to troubleshoot a seemingly simple issue: The callback function of an AJAX post request is receiving a JSON string in the 'data' parameter. {"result":"Torte"} Manually parsing it yields the expected result: var response = JSON.parse(&ap ...

Is there a way to temporarily halt a jQuery animation for 2 seconds before automatically resuming it, without relying on mouse-over or mouse-out triggers?

With just one scrolling image implemented in jQuery, the logos of clients are displayed continuously in a scrolling box with no pauses. Speed can be adjusted easily, but pausing and then resuming the animation after 2 seconds seems to be a challenge whic ...

How can I retrieve the $index value of an ng-repeat element within a uib-dropdown?

I am currently working on implementing an ng-repeat loop that includes a dropdown menu for each element. I want the dropdown menu to contain functions that operate on the specific element, requiring access to the index of that element. Below is the code sn ...

Using Angular 2 to toggle the visibility of a component when hovering over and moving away from it

I have developed a custom filtering component in Angular 2, which I have integrated into the table header. My goal is to show the filter when the mouse hovers over a specific span, and hide it when the mouse moves away. <th> <span class="headCol ...

Occasions focused on the <input type="file"> feature

Looking for a way to write a file input in React that accepts CSV files, validates them, and prevents upload if there are errors? Check out the code snippet below: <CustomInput type="file" id="fileBrowser" name="file" label={filename || 'Choos ...

Attempting to expand the header to span the entire width of the screen using CSS within a WordPress website

I'm currently working on enhancing a WordPress website located at: www.muslimsocialife.com I've developed a child theme based on the parent theme "Januas" (available at: ), and my focus is on adjusting the header to extend the navy blue color se ...

Prevent the top of the fifth row from displaying on mobile devices when the first four rows are hidden

My personal website features a collection of user-generated stories, with only the first 4 rows of each story visible in a fading text gradient from black to white. There is a "show more/less" button to reveal or hide the full content. While this layout ...

What is the best way to send the output of a function once the loop has completed?

Within a Node/Express server written in CoffeeScript, I am working on a function that looks like this: @resolveServers = (url, servers, answer) -> result = [] treatServer(url, server, (treatAnswer) -> result.push(treatAnswer) ) for server ...

Is it possible to dynamically change the color of a box shadow using an event handler?

I'm currently in the process of developing an application that consists of six distinct topics organized within a flexbox structure, complete with a box-shadow effect. My objective is to dynamically alter the color of the box-shadow through an event ...

Autofill feature for styling with CSS within a JavaScript document

Is there a way to enable CSS autocomplete in JavaScript for VS Code? I can easily work with CSS, but the auto suggestions are not showing up when coding in JS. For instance, when typing document.queryselector("myclass")., nothing shows up after the dot li ...

Learn the process of integrating VueJS with RequireJS

I am attempting to set up VueJS with RequireJS. Currently, I am using the following VueJS library: . Below is my configuration file for require: require.config({ baseUrl : "js", paths : { jquery : "libs/jquery-3.2.1.min", fullcalendar : "libs/ful ...