Is it possible to incorporate button classes from the <a> tag into a JQuery fade in/fade out function?

My jQuery image thumb Slider features thumb buttons that link to different div elements.

When a user clicks on a thumb button, I want the associated div to smoothly fade in, replacing the previous one. The goal is to have a seamless transition between the div elements.

Despite spending a lot of time researching jQuery, I'm struggling to find the right solution among the many options available. I feel like there's something missing in my code, but I'm not sure what it is.

Below is the current state of my code:

CSS

Slider

#aemcSlider {
    list-style:none;
    margin-left: 289px;
    width: 474px;
    height: 97px;
    top: 134px;
    position: absolute;
    overflow: hidden;
    left: -3px;
}
#aemcSlider a {
    margin-right: -4px;
}
#aemcPkgContainer {
    z-index:1;
    width: 425px;
    height: 675px;
    position: absolute;
    left: 320px;
    top: 233px;
}
#aemcGroundAdContainer {
    z-index:2;
    display: none;
    width: 425px;
    height: 675px;
    position: absolute;
    left: 320px;
    top: 233px;
}
#aemcClampOnAdContainer {
    z-index:3;
    display: none;
    width: 425px;
    height: 675px;
    position: absolute;
    left: 320px;
    top: 233px;
}
#aemcMetrixContainer {
    z-index:4;
    display: none;
    width: 425px;
    height: 675px;
    position: absolute;
    left: 320px;
    top: 233px;
}

Buttons

//4 buttons like this//

a.aemcGroundFlexBut {
    position:relative;
    float: left;
    margin: 0 auto;
    display: block;
    width: 162px;
    height: 114px;
    background: url(../Images/AEMC_AD_6472-74.png) no-repeat 0 0;
}
a.aemcGroundFlexBut:hover {
    background-position: 0 -114px;
}

HTML

Jquery Slider

<div id="aemcSlider">
    <ul>
        <li><a class="aemcPkgBut" href="#"></a></li>
        <li><a class="aemcGroundFlexBut" href="#"></a></li>
        <li><a class="aemcClampBut" href="#"></a></li>
        <li><a class="aemcMetrixBut" href="#"></a></li>
    </ul>
</div>

Containers:

//There are 4 containers like this//

<div id="aemcPkgContainer">
    <div class="workImage">
        <img src="Images/AEMC_packaging_image.png" alt="Packaging"    
width="295"  hspace="0" vspace="0" border="0" title="Packaging"/>
    </div>
</div>

JS:

// JavaScript Document

$(document).ready(function () {
    $(".aemcPkgBut").click(function () {
        $("#aemcGroundAdContainer").fadeOut(2500);
        $("#aemcClampOnAdContainer").fadeOut(2500);
        $("#aemcMetrixContainer").fadeOut(2500);
        $("#aemcPkgContainer").fadeIn(2500);
    });

    $(".aemcGroundFlexBut").click(function () {
        $("#aemcPkgContainer").fadeOut(2500);
        $("#aemcClampOnAdContainer").fadeOut(2500);
        $("#aemcMetrixContainer").fadeOut(2500);
        $("#aemcGroundAdContainer").fadeIn(2500);
    });

    $(".aemcClampBut").click(function () {
        $("#aemcPkgContainer").fadeOut(2500);
        $("#aemcGroundAdContainer").fadeOut(2500);
        $("#aemcMetrixContainer").fadeOut(2500);
        $("#aemcClampOnAdContainer").fadeIn(2500);
    });

    $(".aemcMetrixBut").click(function () {
        $("#aemcPkgContainer").fadeOut(2500);
        $("#aemcGroundAdContainer").fadeOut(2500);
        $("#aemcClampOnAdContainer").fadeOut(2500);
        $("#aemcMetrixContainer").fadeIn(2500);
    });
});

The current code is not functioning as desired, and I suspect it may have to do with the button type.

If anyone can provide some guidance or assistance, it would be greatly appreciated.

Thank you!

Answer №1

It doesn't seem like it should be an issue... I attempted to utilize your code to reproduce the same behavior.

Take a look at this Fiddle... Hopefully, that will be useful.

Fiddle

$(document).ready(function () {

    $(".aA").click(function () {
        $('#A').fadeIn(1000);
        $('#B').fadeOut(1000);
    });



    $(".aB").click(function () {
        $('#A').fadeOut(1000);
        $('#B').fadeIn(1000);
    }); });

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

Managing simultaneous tasks with multiple event handlers for a single event

Within the realm of HTML, you may encounter an <input type="file"> element that can be linked to one or more event handlers. However, if one event handler includes asynchronous code, it will pause at that point and move on to the next event ...

How can I transfer an instance of a class to dataTransfer.setData?

So I created a new instance of a class: let item = new Item(); Next, I attempted to serialize the item and add it to dataTransfer for drag and drop functionality: ev.dataTransfer.setData("info", JSON.stringify(item)); At some point, I need to retriev ...

Develop a built-in Button for Liking posts

Currently, I am encountering an issue with the JavaScript SDK where I am unable to create a built-in Like button. After researching, I came across this helpful resource: https://developers.facebook.com/docs/opengraph/actions/builtin/likes/ The solution pr ...

What is the recommended method for choosing text colors when creating GUI for app development?

Currently preparing PSDs for the development of both an iOS and Android app. When it comes to coloring text, should I: 1) Utilize #000000 for black text, adjusting opacity to achieve various shades of gray for primary and secondary text? 2) Or opt for a ...

Due to high activity on the main thread, a delay of xxx ms occurred in processing the 'wheel' input event

While using Chrome version: Version 55.0.2883.75 beta (64-bit), along with material-ui (https://github.com/callemall/material-ui) version 0.16.5, and react+react-dom version 15.4.1, an interesting warning message popped up as I scrolled down the page with ...

Incorporate real-time calculations using JavaScript (jQuery) with variables including initialization in HTML code

As a newcomer to JavaScript, I am encountering an issue that I need help with: I would like to convert the value in the number box into the answer next to it without any changes to the value. This should also include the variables NP0, NP1, and DP0 from t ...

How to retrieve the ID of a parent sibling using jQuery DataTables

I have encountered a peculiar issue while trying to retrieve the ID of a table's parent sibling. Prior to initializing jQuery DataTables, obtaining the table's ID poses no problem. However, once it is initialized and the table is built, retrievin ...

Complete a bootstrap row and begin a new row after every nth div element

I have a grid layout in Bootstrap that I will be filling with blog post thumbnails. <section class="container"> <div class="row thumbs"> <div class="col-sm-3">content</div> <div class="col-sm-3">content</div> ...

Is it achievable to have a background image cover size with a responsive rollover effect?

I’m currently facing a unique challenge where I want to have an image as the background of my website, with the size set to cover the entire screen. On this background image, there are elements like buildings that I want to interact with when hovered ove ...

What steps can I take to ensure that when the user clicks the logout button, they are redirected to the home component?

Struggling to find a way to direct the user back to the Home component after logging out. The API functionality has been tested and is working properly. I'm unsure how to properly implement the logout method in the current context to allow for succes ...

redactor.js: Disable backspace functionality when cursor is at the start of a div-container

Currently, I am working with the redactor.js editor that utilizes editable div containers. A challenge I have encountered is when multiple contenteditable containers are nested; deleting content using the backspace button can inadvertently delete the entir ...

Chargebee encountered an error of type TypeError when attempting to create a subscription. The action

Every time I attempt to send a request with Chargebee, an error appears. Error: Failed to create subscription async createSubscriptionForTeamMember(customerId, options) { try { // Proceed with subscription creation using Chargebee API ...

What could be causing my Chrome extension to function on Mac but not on a PC?

I created a basic Chrome extension that includes a background page with the following code: <script type="text/javascript> chrome.tabs.onDetached.addListener(function(tabId, info){ var id = tabId; chrome.tabs.get(id, function(tab) { ...

Insert a CSS Class into an HTML div element with JQuery

I'm faced with a bit of a challenge. Here's the scenario: <div class="portItem"></div> <div class="portItem"></div> <div class="portItem"></div> <div class="p ...

Is there a way to launch Visual Studio Code using a web browser?

Is there a way to launch "Visual Studio Code" automatically upon clicking a button on my website? ...

I am looking to implement a feature in my quiz application where a green tick mark appears next to the question number for the correct answer and a red cross mark for the wrong answer

My HTML code here retrieves questions from a database and displays them based on the question number. <h4>{{indexOfelement+1}}</h4>&nbsp;&nbsp; In my CSS, I need to style the questions as follows: How can I achieve this? Each question ...

Tips on displaying inline span text within an anchor element, above the anchor text

Check out the code I've created below: .tooltip1 { z-index: 1; position: relative; } .tooltip1 .tooltiptext { visibility: hidden; width: 300px; ...

receiving unexpected data while using AJAX

For my PHP project, I have a function that validates a textbox using AJAX. The AJAX is working fine, but it only gives the following output for $return_value==-4 "<br /> <font size='1'><table class='xdebug-error xe-deprecated ...

executing a hook within _app.tsx in Next.js

The issue I'm facing involves the rendering of a hook that helps determine if my components are within the screen's view to trigger animations. This hook is executed in _app.tsx, however, it doesn't run when switching to another page. Oddly ...