The tabs are stagnant and not refreshing

I have set up a tabbed layout on one of the pages of my website with different content in each tab. The tabs are clickable and change the displayed content. However, I am experiencing an issue where the initial tab's content is not showing up after switching to another tab and back again. Could this be due to the absence of a server or is there an error in my code? Additionally, when I add content to the other tab divs, none of them show up upon refreshing the page and clicking on the respective tabs. Only the content of the first tab is visible. Thank you for your help.

<!DOCTYPE html>
<html>
<head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="./common/res.css"/>
    <meta charset="utf-8">
    <title>Room Reservation</title>
</head>
<header>
    <script type="text/javascript" src="./common/tab.js"></script>
</header>
<body>
    <div class="tabs">
        <ul class="tab-links">
            <li class="active"><a href="#tab1">Stage</a></li>
            <li><a href="#tab2">Studio</a></li>
            <li><a href="#tab3">Session</a></li>
        </ul>

<div class="tab-content">
    <div id="tab1" class="tab active">
        <form required>
            Room Selection:<br>
            <select name="room">
                <option value="stage">Stage Access</option>
                <option value="grip">Grip Closet</option>
                <option value="grid">Grid</option>
            </select> <br><br>
        </form>
     <p style="color:red;">In order to gain access to the stage you must pick up the access key from the Rental House.</p><br>
     <textarea readonly id="policy" rows="8" cols="30" placeholder="Policy Summary will go here"></textarea><br><br>
     <input required type="radio" id="agree">I agree I have read and understand the policy stated above and have read the full liability form.<br><br>
     <div id="cal">
        <iframe src="https://calendar.google.com/calendar/embed?showPrint=0&amp;showTabs=0&amp;mode=WEEK&amp;height=600&amp;wkst=1&amp;bgcolor=%23FFFFFF&amp;ctz=America%2FNew_York" width="800" height="600" frameborder="0"></iframe>
     </div><br>
     <form target="_blank" action="https://mediaservices.champlain.edu/webcheckout/pir/login">
         <input type="submit" value="Confirm">
     </form>
    </div>
    <div id="tab2" class="tab">
         <form required>
            Room Selection:<br>
            <select name="studioroom">
                <option value="control">Control Room A</option>
                <option value="isob">Isolation Room B</option>
                <option value="isoc">Isolation Room C</option>
            </select> <br><br>
        </form>
    </div>

    <div id="tab3" class="tab">
    </div>
</div>
</div>
<script>
jQuery(document).ready(function() {
    jQuery('.tabs .tab-links li').on('click', function(e)  {
    tabs(jQuery(this).attr('data-toggle'));
    jQuery(this).addClass('active').siblings().removeClass('active');
    });

    function tabs(tab) {
        jQuery('.tab-content .tab').hide()
        jQuery('.tab-content').find(tab).show();
    }
});
</script>
</body>
</html>


/*----- Tabs -----*/
.tabs {
width:100%;
display:inline-block;
}

/*----- Tab Links -----*/
/* Clearfix */
.tab-links:after {
    display:block;
    clear:both;
    content:'';
}

.tab-links li {
    margin:0px 5px;
    float:left;
    list-style:none;
}

    .tab-links a {
        padding:9px 15px;
        display:inline-block;
        border-radius:3px 3px 0px 0px;
        background:#7FB5DA;
        font-size:16px;
        font-weight:600;
        color:#4c4c4c;
        transition:all linear 0.15s;
    }

    .tab-links a:hover {
        background:#a7cce5;
        text-decoration:none;
    }

li.active a, li.active a:hover {
    background:#fff;
    color:#4c4c4c;
}

/*----- Content of Tabs -----*/
.tab-content {
    padding:15px;
    border-radius:3px;
    box-shadow:-1px 1px 1px rgba(0,0,0,0.15);
    background:#fff;
}

    .tab {
        display:none;
    }

    .tab.active {
        display:block;
    }

Answer №1

Here is the issue you are facing:

 jQuery(this).attr('data-toggle')

When clicking on an li element (referred to as this), you are attempting to retrieve the data-toggle attribute, which does not exist.

Instead, you need to access the href attribute of the anchor tag within the clicked li element.

Resolution:

jQuery(this).find("a").attr('href')

View working example on jsfiddle

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

I attempted to navigate through the website but could not locate any page links

Currently, I am contemplating extracting data from a particular webpage using selenium and BeautifulSoup. However, upon inspecting the HTML code, I was unable to find the link for the page numbers. Any assistance would be greatly appreciated. ...

Creating a fixed navigation bar that stays at the top of the page when scrolling

I am trying to create a navigation bar similar to the one seen on W3School's website. I would like the navigation bar to overlap the header when scrolling down, and for the header to appear above the nav bar when scrolling back to the top. Despite m ...

What are some alternative ways to create a text field with the same style as Material UI's without relying on the Material UI

With the power of HTML, CSS, and Reactjs I am aiming to create a functionality where the placeholder animates up to the border upon clicking on the text field An example can be seen with Material UI text field: https://material-ui.com/components/text-fie ...

Customizing Images using a JSON array of images

Looking to implement a feature that displays images fetched from a CMS via a JSON file. The JSON data structure is as follows: { "images": [ {"title": "Image One", "url": "image1.jpg"}, {"title": "Image Two", "url": "image2.jpg"}, {"title": "Ima ...

What steps can be taken to turn this html code and css into a mobile application?

I have begun working on my HTML and CSS but need some guidance to create a mobile app without needing to resize it when accessed through the web. Additionally, I would like to make it responsive in CSS. Can you provide me with the necessary code? @c ...

What can be done when the enter key is not sent by Selenium-js, despite the sendKeys function working properly?

My challenge lies with an element <input> that I interact with using await element.sendKeys("example"). This action consistently works without any issues. However, when I immediately follow this with await element.sendKeys(Key.ENTER), noth ...

How about crafting a brand new div element?

Creating a new div using JavaScript should be simple, but I'm struggling with it. I've seen many solutions online, but none seem to work for me. I want to generate a new div element, assign it an ID, and style it using CSS. I have tried using doc ...

Adding or removing a class on hover in Tailwind: The simple way!

Is there a way to change the class upon hovering an object using tailwind classes? <span className='group inline-block relative'> Hello <span className='hidden absolute -top-16 left-16 group-hover:inline-block'>&#45; ...

Changing the CSS from "position: fixed" to "position: absolute"

Is there a way to make the div .box fixed within an absolute position div? My code doesn't seem to work, any suggestions on how to achieve this? .container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width ...

Utilize MaterialUI's stepper component to jazz up your design with

Is there a way to customize the color of a material ui Stepper? By default, the material UI stepper's icons use the primary color for both "active" and "completed" steps. class HorizontalLinearStepper extends React.Component { state = { activeS ...

The pictures in a <div> tag are not showing up

Functionality: I have set up 2 different <div> elements with unique IDs. Each of these <div> elements will make an ajax call to fetch a specific set of images for display. To summarize, both <div> elements are invoking the same ajax met ...

Using Javascript to change CSS in a Polymer application

Coming from a background in angular and react, I am now delving into the world of polymer. I have a polymer class called myClass with the following template. <div id="[[x]]"> Here, 'x' is a property defined in a property getter. stat ...

Unable to showcase image on Django webpage

I placed my image file img.png and HTML file index.html together in a folder named test. When I ran index.html in Django, I wanted to display the image locally. I attempted to do so using the following: <img src='img.png'/> <img src ...

What is the best way to send various variables using an onclick event?

My action plan was as follows: $(document).on("click", "#deleteMe", function (){ var id = $(this).data("id"); console.log(id); // the function responsible for deleting the event using its id belongs here }); The HTML for my delete button lo ...

Eliminate any line breaks that were generated by the div containing map information

I'm currently facing an issue with creating a map where I am adding pins using CSS coordinates. Every time I add a new pin div, it creates additional line breaks beneath the map. This could become problematic as I have around 130 pins to add in total. ...

Tips for seamlessly incorporating advertisements into a mixed application

I am having trouble adding banner ads to my hybrid application developed with Telerik. Despite my extensive research, I have been unable to find a suitable solution. Is there any html5 or javascript banner advertising service/API that is compatible with ...

Tips for properly formatting JSON in JavaScript

View Model function CustomerInformation() { var vm = this; vm.CustomerInfo = { "customerId": "", "customerTitle": "", "customerName": "" }; return vm; } Global Variables (function () { 'use strict'; v ...

Resolving the Table Issue with 'onclick' in Javascript

Apologies for the lack of creativity in the title, I struggled to come up with something fitting. Currently, I am engaged in the development of a user-friendly WYSIWYG site builder. However, I have encountered an obstacle along the way. I've devised ...

DataFrame in Python Jupyter Notebook featuring stylish borders

In my Jupyter notebook, I am trying to enhance the appearance of a data frame by adding borders using the following code: %%HTML <style type="text/css"> table.dataframe td, table.dataframe th { border: 1px black solid !important; co ...

Nested for loop utilized to create a typewriting effect

I've tried various methods to create a typing effect, but I'm struggling with understanding the concept of using nested for loops. var changingtext = document.querySelector(".text"); var arr = ["challenging","Exciting&qu ...