Tips for concealing specific sections or content on a tab

I am looking to implement a layout with 4 tabs where the content of each tab is initially hidden and only becomes visible when that specific tab is clicked. For example, if the user clicks on the 1st tab, then the content associated with that tab should appear.

Answer №1

Feel free to give this a shot.

      $('.tab_wrpaper').on('click',".tab > li",function(e){
            e.preventDefault();

            var data_id = $(this).attr('data-id');
            $(".tab li").removeClass("nav-tab-active"); // remove active class from tab list item
            $(this).addClass("nav-tab-active"); // add active class to the clicked list item
            $(".tab-content .tab-pane").removeClass("active");  // remove active class from tab content 
            $(".tab-pane[data-id='tab_" + data_id + 
             "']").addClass("active");   // add active class to selected tab content
        
       });
<div class="tab_wrapper">
        <div class="tab">
            <li data-id="tab_a">Tab A</li>
            <li data-id="tab_b">Tab B</li>
        </div>
        <div class="tab-content">
            <div class="tab-pane" data-id="tab_a">Content A</div>
            <div class="tab-pane" data-id="tab_b">Content B</div>
        </div>
    </div>

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

Steps for generating an array entry containing an ObjectId and a Number

I am a newbie when it comes to mongodb and I am attempting to create an entry like this: { "resources": [ { "amount": 1, "resource": { "_id": "61be82b9549b4ede ...

What is the method for setting an image to stretch and fill the divided screen?

I'm having trouble getting my image to fill the screen correctly on a split screen. The top half of the screen has an image, while the bottom half has text. No matter what I do, there always seems to be a blank space either at the top of the image or ...

Can all anchor tags properties on a website be simultaneously changed?

Recently, I discovered that using target="_blank" in anchor tags can leave a website vulnerable to security risks, and the recommended alternative is to use rel="noopener". In my current web project, all anchor tags are currently utilizing the target attri ...

What is the best way to modify a React ref when the child elements of ref.current are altered?

I'm currently utilizing React refs for managing click events outside of an element. import { useEffect } from 'react'; export const useClickOutside = (ref, callback = () => {}) => { const handleClick = e => { if (ref.current ...

Utilizing PHP Variables in JavaScript: A Comprehensive Guide

Is there a way to work around the inability to directly use PHP variables in javascript code? I need to incorporate these parameters into my javascript: username: '<?php echo $user_id;?>.example.co.uk', password: 'example', Inst ...

AngularJS POST request encounters failure: Preflight response contains improperly formatted HTTP status code 404

I have encountered a persistent issue with microframeworks while attempting to perform a simple POST request. Despite trying multiple frameworks, none of them seem to handle the POST request properly: Here is an example using AngularJS on the client side: ...

Can you please explain the primary distinction between these two identification numbers?

Can you explain the distinction between the following two css ids? p#id1 { insert code here } and #id1 p { insert code here } ...

Populating a two-dimensional array with randomly generated numbers using javascript

Apologies if this has been asked before, but I couldn't find any previous posts on the topic as I'm still fairly new to this site! Lately, I've been exploring game development using HTML5 and JavaScript and have gotten into creating tileset ...

Cache items in a list that require a callback function

I am facing a challenge with a list of checkboxes that I display on my website. Every time I click on one checkbox, it is added or removed from a selection that I maintain. This process is handled by a callback function. The issue arises when the number of ...

Pull data from one array of objects using the id from another array to display in a list using AngularJS ng-repeat

After retrieving a list of options, I make an API call to validate each option. The goal is to display whether each option is valid or not. My starting array looks like: $scope.preValidationArray = [ { id: 1, description: 'Item 1' }, { id: 2 ...

Tallying outcomes using JavaScript

I encountered a particular challenge: I have designed a table for user interaction, with results displayed at the end of each row. Just out of curiosity, I would like to count how many results are present in the table without performing any calculations. I ...

Trying to modify a read-only property in React Native, got the error message "Attempted to assign to

Reflecting on My Journey(feel free to skip ahead) Recently, I delved into the world of mobile development with react-native, and let me tell you, it was a rollercoaster. After spending hours troubleshooting why my react-native init project wouldn't e ...

Is utilizing the correct use case for a Bunyan child logger?

I've recently started exploring bunyan for logging in my nodejs application. After giving it a try, everything seems to be functioning quite smoothly. Initially, I overlooked a section on log.child, but now I am eager to understand its usage. It appea ...

Having trouble removing just one element from an array in Redux. Any suggestions on how to make it work properly?

I'm currently working on creating a dynamic algorithm for removing an item from an array. Reducer: import { LOAD_PAGES, REMOVE_PAGE } from "./dynamicMenuActions"; export const initialState = { pages: [] }; export const dynamicMenuReducer = (state ...

Ways to maintain an array in Vuex even after mutations take place? (Specifically focusing on persisting data through browser refresh)

I am in the process of developing a basic shopping cart and I need guidance on how to persist an array containing cart data when executing the addProduct mutation below. Is there a way to save this data temporarily to prevent it from being lost due to br ...

Can you explain the functionality of dismissing a Bootstrap alert?

In this example, we can see how Bootstrap handles dismissible alerts: <div class="alert alert-warning alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidde ...

Achieving inline navigation with hover effects

Could someone help me with creating a HTML Navbar that displays inline and has a hover effect? This is the HTML code I have been working on: <nav class="navbar navbar-light bg-faded" style="background-color: #c8c8c8"> <div class="container-flu ...

jQuery not refreshing properly

I'm currently in the process of creating a script to switch the language on a website using PHP and Ajax/jQuery. I would like the page content to refresh without having to reload the entire page. So far, this is what I have come up with: $( "a[data-r ...

selenium extraction failure

I am attempting to log in to this specific website using selenium. I've imported the web driver and Keys module in order to input my login information into the required fields on the page. from selenium import webdriver from selenium.webdriver.common. ...

Click on the spliced image to alter the table

Seeking assistance with jquery as a beginner. I have three tables containing spliced images, each with its own id. When an image in one table is clicked, I want the entire table to switch to another one with a different id. Struggling to figure out how to ...