The fadeOut method does not support the removeClass function

I've encountered a small issue while trying to create a slider with images. As someone who is new to javascript and jquery, I attempted to build it based on my past experience with Codeacademy. However, the code that used to work fine there is now causing an error when I click the previous arrow. The console displays the message "Uncaught TypeError: currentSlide.fadeOut(...).removeCLass is not a function".

Here is the code snippet:

HTML:

<div class="slider">
    <div class="slide slide1 active-slide">
    </div>
    <div class="slide slide2">
    </div>
    <div class="slide slide3">
    </div>
    <div class="slide slide4">
    </div>
</div>

<div class="slider-nav">
    <a href="#" class="arrow-prev"><img src="images/props/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/props/arrow-next.png"></a>
</div>

CSS:

.slider{
    position:relative;
    width:100%;
    height:550px;
}
.slide{
    background-size:cover;
    background-repeat:no-repeat;
    background-position:center;
    display:none;
    position:absolute;
    top:0;
    left:0;
    width:100%;
}
.slide1{
    background-image:url('images/main/slider/1.jpg');
    height:100%
}
.slide2{
    background-image:url('images/main/slider/2.jpg');
    height:100%
}
.slide3{
    background-image:url('images/main/slider/3.jpg');
    height:100%
}
.slide4{
    background-image:url('images/main/slider/4.jpg');
    height:100%
}
.active-slide{
    display:block;
}

JAVASCRIPT:

var main = function(){

    $('.arrow-next').click(function(){
       var currentSlide = $('.active-slide');
       var nextSlide = currentSlide.next();

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

       currentSlide.fadeOut(600).removeClass('active-slide');
       nextSlide.fadeIn(600).addClass('active-slide');

       currentDot = $('.active-dot');
       nextDot = currentDot.next();

       if (nextDot.length == 0){
        nextDot = $('.dot').first();   
       }

       currentDot.removeClass('active-dot');
       nextDot.addClass('active-dot');
    });

    $('.arrow-prev').click(function(){
       var currentSlide = $('.active-slide');
       var prevSlide = currentSlide.prev();

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

       currentSlide.fadeOut(600).removeCLass('active-slide');
       prevSlide.fadeIn(600).addClass('active-slide');

       currentDot = $('.active-dot');
       prevDot = currentDot.prev();

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

       currentDot.removeClass('active-dot');
       prevDot.addClass('active-dot');
    });
};

$(document).ready(main);

Answer №1

Initially, I noticed that you used removeCLass instead of removeClass with a capital letter "L"

Perhaps this was an oversight on your part.

Alternatively, it could be due to using the wrong version of jQuery.

When I attempted the following code snippet:

$("body").fadeOut(600).addClass("hello") 

the operation executed without any 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

Using Selenium Webdriver to initiate the play function of a video by clicking on the control

Is there a way to play the video on this page by clicking the play button? I noticed a 'playpause' control in the JavaScript, but I'm unsure how to activate it. <div id="videoModal" class="reveal-modal expand open" style="display: block ...

What is the best method for globally configuring the Angular moment timezone?

I integrated angular moment js into my angular application. I am looking to display the date and time based on the time zone of the user accessing the app. However, I am facing difficulty in applying the time zone globally throughout my application. https ...

Adjust webpage display with JavaScript

Utilizing the mobile-first approach of Zurb Foundation, I successfully created a responsive design. However, my client now requires a direct link labeled "View desktop version" in the footer for when the website is accessed on mobile devices or tablets. T ...

Unable to retrieve variable from ajax success function in response

In my MVC view, I have an ajax call that triggers a chain of 5 functions before completion. Each function contains an if/else statement to return its own error message in case of failure, requiring the original page to be reloaded to display the errors. Ho ...

Is it possible to handle both ajax form submissions and browser post submissions in express.js?

On my website, I have implemented a contact form using express.js (4.0). I am contemplating how to manage the scenario where a user disables JavaScript. If the last part of my routing function looks like this: res.render('contact.jade', { tit ...

The current object is not being referenced by this specific keyword

I am encountering an issue in my React application where I am trying to set the state of a child component using this.props, but it is showing an error saying props is undefined. It seems like 'this' is not referencing the current object correctl ...

What is the best way to iterate through a JSON object in a subsequent AJAX call

Is there a way to loop through all the number channels in the JSON file? I have numerous numbers and I would like to display them one by one: alert(res.available_channels[1].num); and continue until... alert(res.available_channels[***].num); http://js ...

Is there a way to programmatically emulate Firebug's inspect element feature using JavaScript?

Is there a straightforward method in JavaScript or any popular libraries like YUI or jQuery to allow users to interact with elements on a website, similar to the functionality of Firebug for developers? ...

Analyzing the date provided as a string and comparing it to the current date using HTML and JavaScript

<html> <head> <script lang="Javascript"> function validateExpDate(){ var expdate ="24-10-2018"; var fields = expdate.split('-'); var date = parseInt(fields[0]); var month = parseInt(fields[1]); var year = parseIn ...

Encountering an issue with executing Google API Geocode in JavaScript

I'm having trouble printing an address on the console log. Every time I run the code, I encounter an error message that reads: { "error_message" : "Invalid request. Missing the 'address', 'components', 'latlng' or &ap ...

The jQuery execCommand feature fails to generate a pop-up when used within the contenteditable attribute of an HTML tag

Trying to implement an inline text editor using the jQuery execCommand function. Below is a snippet of my source code: /*******************************************************************/ /********** Click: inner of contenteditable text-editor div *** ...

Displaying a loading image using the getJSON method

I'm in need of a loading image to display while fetching data with AJAX using getJSON. I've searched for a solution but haven't come across the best method yet. Can you advise on the most effective approach to achieve this? $.getJSON(' ...

Sending a data value from a Controller to jQuery in CodeIgniter

Getting straight to the point. Check out some of the functions from my Student Model: public function get_exam_data($exam_id){ $this->db->select('exam_id, exam_name, duration'); $this->db->from('exams'); $this- ...

Maximizing the performance of shader color calls

Exploring shaders with Three.js is a new challenge for me, and I'm struggling to modify some crucial code without just adjusting the RGBA values. One limitation I face is being unable to enclose it within an .html() method. My goal is to apply 10 diff ...

In order to determine if components linked from anchor elements are visible on the screen in Next.js, a thorough examination of the components

Currently, I am in the process of developing my own single-page website using Next.js and Typescript. The site consists of two sections: one (component 1) displaying my name and three anchor elements with a 'sticky' setting for easy navigation, a ...

A guide on extracting the current website URL in a React application

I wanted to find a method to duplicate the text from a URL so that users could easily share the link with others. ...

Can a form be designed to submit a list separated by commas through a GET request?

Imagine having a form that includes multiple checkboxes under the same name, c. Each checkbox is assigned an integer value. Upon submitting the form using GET method, the desired URL format is www.url.com/?c=1,2,3,4,5 rather than www.url.com/?c=1&c= ...

Different ways to modify the style of a MenuItem component in PrimeNG

Seeking advice on customizing the look of a MenuItem in PrimeNG. Here's what I have attempted so far: <p-menu [style]="{'width': '400px'}" #menuOpcoesLista popup="popup" [model]="opcoesListaCS" appendTo="body"></p-menu> ...

The term 'undefined' does not refer to an object

My div contains the following code: <em id="ProductPrice" class="ProductPrice VariationProductPrice">$75.00</em> I want to change the text color if the value changes. This is what I tried: <script> $(document).ajaxSuccess(function(){ ...

Retrieve MySQL records based on checkbox selection status and export them to Microsoft Excel

I am trying to create a dynamic HTML form using PHP. The form includes checkboxes that, when selected, should fetch corresponding records from a MySQL database. Only the CustomerID associated with the checked checkboxes should be exported to an Excel file; ...