Toggle the visibility of multiple DIVs within a table row, with fading effects, while also displaying various hyperlinks in another row and columns

Hello there, I have a specific requirement that I need help with...

In my layout, I have 3 links placed in 3 columns within a single row. Underneath, there is another row containing 1 column with 3 div elements inside it. My question is: How can I achieve a fade in/fade out effect for these divs when the links are clicked?

  • Initially, all the content within #info... is hidden.
  • When Link 1 is clicked, #info-first fades in. Subsequently, if Link 2 is clicked, #info-first fades out and #info-second fades in, and so on for all the Links.
  • There should also be an option to hide all the #info-... content and revert back to the initial state (all hidden).

For a simple demonstration, please check this JSFiddle link.

UPDATE: SOLUTION

Credits to Eduardo for providing the final solution. You can view it on this JSFiddle page.

HTML:

<div id="banner-content-wrap">
<div class="banner-text"><span>Awesome</span> slogan goes here. <span>Very cool</span> indeed.
    <br/>
    <div id="explain">At the start, all #info... content is hidden. Clicking on Link 1 makes #info-first appear. Subsequent clicks on other Links control the fading in and out of corresponding info sections.</div>
    <div class="banner-links">
        <table border="1">
            <tr class="first">
                <td class="first">about</td>
                <td class="second">about</td>
                <td class="third">about</td>
            </tr>
            <tr class="second">
                <td class="first><a href="#">LINK 1</a></td>
                <td class="second"><a href="#">LINK 2</a></td>
                <td class="third"><a href="#">LINK 3</a></td>
            </tr>
            <tr class="third">
                <td colspan="3">
                    <div id="info">
                        <div class="info-first">Link 1 triggers #info-first visibility
                            <br/>
                            <br/><a href="#">HIDE #info-first</a>
                        </div>
                        <div class="info-second">Clicking Link 2 reveals #info-second details
                            <br/>
                            <br/><a href="#">HIDE #info-second</a>
                        </div>
                        <div class="info-third">Link 3 unveils #info-third information
                            <br/>
                            <br/><a href="#">HIDE #info-third</a>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
</div>

CSS:

#banner-content-wrap {
    position: absolute;
    top: 25%;
    width: 960px;
    right: 50%;
    margin-right: -480px;
}
#explain {
    text-align: center;
    font-size: 12px;
    color: #000;
}
.banner-text {
    text-align: center;
    position: absolute;
    height: 80px;
    width: 950px;
    overflow: hidden;
    padding: 0;
    overflow: visible;
    font-size: 36px;
    font-family:'Berlin Sans FB';
    color: #fff;
    text-shadow: 0px -1px 8px rgba(0, 0, 0, 0.33);
}
.banner-text span {
    color: #000;
}
.banner-links table {
    width: 400px;
    margin-left: auto;
    margin-right: auto;
    padding-top: 25px;
    border-collapse:collapse;
}
.banner-links tr.first td.first {
    text-align: center;
    padding-right: 50px;
}
.banner-links tr.first td.second {
    text-align: center;
}
.banner-links tr.first td.third {
    text-align: center;
    padding-left: 50px;
}
.banner-links tr.first {
    font-size: 10px;
    font-family:'Verdana';
    color: #000;
    text-shadow: 0px 0px 4px rgba(0, 0, 0, 0.33);
    opacity: 0.75;
    -webkit-transition: 0.5s; /* For Safari 3.1 to 6.0 */
    transition: 0.5s;
}
.banner-links tr.second td.first {
    text-align: center;
    padding-right: 50px;
}
.banner-links tr.second td.second {
    text-align: center;
}
.banner-links tr.second td.third {
    text-align: center;
    padding-left: 50px;
}
.banner-links tr.second {
line-height: 24px;
}
.banner-links tr.second a {
    text-transform: uppercase;
    font-size: 18px;
    font-family:'Verdana';
    color: #000;
    text-shadow: 0px -1px 8px rgba(0, 0, 0, 0.33);
    opacity: 0.75;
    -webkit-transition: 0.5s; /* For Safari 3.1 to 6.0 */
    transition: 0.5s;
}
.banner-links tr.second a:hover {
    opacity: 0.95;
}
.banner-links tr.second td.first a:hover {
    color: #ff0000;
}
.banner-links tr.second td.second a:hover {
color: #34b700;
}
.banner-links tr.second td.third a:hover {
    color: #004eb7;
}
.banner-links tr.third td {
    background: transparent;
    width: 100%;
}
.banner-links #info {
    font-size: 12px;
    font-family:'Verdana';
    text-align: left;
    background: rgba(255, 255, 255, 0.33);
}
.banner-links .info-first {
    background: #ff0000;
    padding: 10px 10px 10px 10px;
}
.banner-links .info-second {
    background: #34b700;
    padding: 10px 10px 10px 10px;
}
.banner-links .info-third {
    background: #004eb7;
    padding: 10px 10px 10px 10px;
}

Answer №1

If you use the fadeToggle() function, it will effectively hide or show elements. Another option is to utilize CSS to conceal elements with the class info-(something).

$(".second td").click(function(){
   $(".info-"+$(this).attr("class")).fadeToggle()
});

By clicking on a td within .second, we dynamically set the selector for the corresponding divs and then apply fadeToggle() to toggle their visibility.

div[class^='info-']{
    display:none;
 }

This snippet hides any div with a class that begins with "info-".

For a practical demonstration, refer to this JSFiddle link.

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

Looking to showcase Unicode characters with jQuery AJAX - here's how!

I am currently working on retrieving unicode characters from a MySQL server using PHP, Ajax, and jQuery in the code snippet below. $.post("test.php",{tableName: A_table}, function(data) { $.each($(data), function(key, value) { ...

The dual-sided transparent shader appears glitchy

Welcome to my shader experiment using three.js in a 3D environment. The scene features a sphere displaying a demo shader I created, which incorporates a simple 2D noise implementation. The shader presents a visually striking effect with one side of the sp ...

using jquery to fill in fields in a table form

I am currently working with a basic html table that initially has two rows, each containing 2 form fields. Users have the ability to add more rows to the table by following this process: $('a#addRow').click(function() { $('#jTable tr:la ...

I'm encountering an issue where the data in my personalDeatail model's add value is not updating automatically. Can someone please help me

I've been struggling to automatically update the data in model personalDetail.add value when adding two column data. The added data appears correctly in the input box, but it's not updating in personalDetail.add. What am I missing here? Help need ...

Step-by-step guide on utilizing jQuery to fade out all elements except the one that is selected

There are multiple li elements created in this way: echo '<ul>'; foreach ($test as $value){ echo '<li class="li_class">.$value['name'].</li>'; } echo '</ul>'; This code will generate the fol ...

Incorrect rendering on mobile screen width

I am facing an issue where my div does not display as 100% width in the mobile version. Below is the JSX code I am using: <div> <div expand="lg" className="login-header"> <h1>logo</h1> <h1&g ...

Creating personalized Date and Time formatting on the X axis in Lightningchart JS

I have an X-axis representing time intervals in 15-second increments. ["2020-05-22 14:20:22", "173.9"] ["2020-05-22 14:20:40", "175.3"] ["2020-05-22 14:20:58", "172.4"] In my attempt to add this data to the chart, I used the following code: for(var key ...

Implement a Selection Feature in Angular

Currently, I am working on an application where users can add new rows with the same fields. One of the requirements is to allow users to add an option to a select element. While I have successfully implemented this in jQuery, I am facing challenges integr ...

Node.js causing excessive CPU usage due to repeated gettimeofday calls

Recently, I encountered a situation with a long-running node.js process that would occasionally spike to 100% CPU usage and stop responding to requests. In an effort to diagnose the issue, I used strace to inspect the process and discovered a series of get ...

I incorporated the href attribute within the ordered list in my HTML code, but unfortunately, the content is not displaying in a properly sequential format

I am looking for a specific output The desired output format is not being achieved, instead my results appear as an unformatted list. This is the result I obtained Here is what I received And this is what I actually want Thank you ...

Is there a method to ensure that the window event always gets triggered before any other events?

Is there a way to make the window event trigger first when clicking on #myDiv? (function ($, w, d) { $(d).ready(function () { $(w).click(function() { alert('window has been clicked'); }); $('#myDiv').cl ...

Exploring HTML elements using CSS Selectors in Scrapy with Python

Currently, I am working on a personal project to create a web crawler that extracts information from Yahoo Finance. However, I have encountered an issue while trying to pull a specific value from the analysis page on Yahoo Finance. The complexity of the HT ...

Filtering visibility of bootstrap cards based on card content

I am having trouble with a seemingly simple task. I have a grid of cards that have the following structure: <div class="card"> <img src="data:image/jpg;base64,{{ books[book]['cover']}}" class="card-img-top" ...

Having trouble retrieving the Node.js file via a POST request

After coming across similar questions without a solution, I am reaching out for help here. I have generated XML content programmatically and displayed it in a Textarea. Now, I need to provide an option for users to export or download this content to their ...

What is the best way to separate an ellipse into evenly sized portions?

This function is used to determine the coordinates of a vertex on an ellipse: function calculateEllipse(a, b, angle) { var alpha = angle * (Math.PI / 180) ; var sinalpha = Math.sin(alpha); var cosalpha = Math.cos(alpha); var X = a * cosa ...

My text is engulfed by a mesmerizing animated background

My project involves incorporating an animated background that I found on CodePen. However, when I try to add text or titles over the animation, they do not display correctly. This is my first time using this site and I could really use some assistance. T ...

My code gets disrupted when I switch between ids and classes

I'm currently learning about javascript and jquery, attempting to implement various scripts. I successfully executed the following script: jQuery(document).ready(function($) { var scroll_start = 0; var startchange = $('#homepage-header' ...

Enhance the functionality of NodeJS core applications

I recently attempted to modify some custom functions in the FS module of NodeJS, which is an integral part of NodeJS' core modules. The specific file I targeted was fs.js, located in /usr/lib/nodejs. However, despite making changes to the code, I noti ...

What is the method for ensuring that the delete functionality is displayed within the same row?

In my division, there are options for names and deletion. It is displayed on my website as: 1.jpg delete The HTML code for the division is: <div id="files1" class="files"> <b class='dataname' >1.jpg</b> <span cla ...

Expanding the content width of Bootstrap Nav Pills

I'm currently working with Bootstrap pills that feature two tabs. I would like to customize the width of the tab content container differently for each tab, but I'm unsure how to achieve this. The tab-content class currently sets the same width f ...