Showcasing top performers via JavaScript tabs

I have two tabs on my webpage: "Overall Leaderboard" and "Weekly Leaderboard". Each tab displays a leaderboard with different scores.

When I click on the "Overall Leaderboard" tab, it shows a leaderboard with specific scores.

Now, my question is how can I make the "Weekly Leaderboard" tab display another leaderboard but maintain the same style using CSS?

Any assistance in achieving this would be greatly appreciated!

$(document).ready(function() {
  $('.tab a').on('click', function(e) {
    e.preventDefault();
    var _this = $(this);
    var block = _this.attr('href');
    if (block == "#leaderboard") {
      $(block).fadeIn();
      $('#login').hide();
      $(document).find('.active').removeClass("active");
      $(this).parent().addClass("active");
    }
    if (block == "#login") {
      $(block).fadeIn();
      $('#leaderboard').hide();
      $(document).find('.active').removeClass("active");
      $(this).parent().addClass("active");
    }
  });

  $('.tab.active a').click(); // Default open
});
/* Include your CSS code here */
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Leaderboards</title>
  <link href='http://fonts.googleapis.com/css?family=Titillium+Web:400,300,600' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="css/style.css">

</head>

<body>
  <div class="form">

    <ul class="tab-group">
      <li class="tab active"><a href="#leaderboard">Overall Leaderboard</a>
      </li>
      <li class="tab"><a href="#login">Weekly Leaderboard</a>
      </li>
    </ul>

    <div class="tab-content">
      <div id="signup">
        <div class="leaderboard" id="leaderboard">
          <ol>
            <li>
              <mark>Jerry Wood</mark>
              <small>315</small>
            </li>
            <!-- Add more leaderboard data here -->
          </ol>
        </div>
      </div>

      <div id="login">
        <h1></h1>
        <form action="/" method="post">
          <div class="leaderboard" id="leaderboard">
            <ol>
              <li>
                <mark>Jerry Wood</mark>
                <small>45</small>
              </li>
              <!-- Add more leaderboard data here -->
            </ol>
          </div>
        </form>
      </div>
    </div>
    <!-- tab-content -->
  </div>
  <!-- /form -->

  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
  <script src="js/index.js"></script>
</body>

</html>

You can view the image here.

Check out the Fiddle link for more details: here.

Answer №1

Please refer to the following source code for more details:

$(document).ready(function () {
                $('.tab a').on('click', function (e) {
                    e.preventDefault();
                    var _this = $(this);
                    var block = _this.attr('href');
                    $(".tab").removeClass("active");
                    _this.parent().addClass("active");
                    if (block == "#signup") {
                       $(block).fadeIn();
                        $('#login').hide();
                    }
                    if (block == "#login") {
                        $(block).fadeIn();
                        $('#signup').hide(); 
                    }
                });
            });
*,
            *:before,
            *:after {
                box-sizing: border-box;
            }

            html {
                overflow-y: scroll;
            }

            // More CSS code here...
 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <div class="form">

            <ul class="tab-group">
                <li class="tab active"><a href="#signup">LeaderBoard</a></li>
                <li class="tab"><a href="#login">MedalTally</a></li>
            </ul>

            // More HTML code here...

        </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

What steps can I take to properly position my child element within its parent container?

Is there a way to adjust the width of a child element so it fits snugly inside its parent div? The width should be contained within the padding area. The top and left placement is correct, but the right side needs adjustment. Check out this link for refe ...

"Utilizing Bootstrap's Table Features within the Moodle Platform

Hey there! I'm currently in the process of updating a client's Moodle website. Our goal is to create responsive tables on the homepage, but I've encountered some challenges. Due to conflicts with other Moodle libraries, I wasn't able to ...

What is the best way to utilize an onClick on a button to update a value that is being utilized in a useEffect hook?

I am looking for a way to dynamically change the content displayed in this section without navigating to another page. I have two sets of data - one displaying all blogs and the other showing only blogs authored by "mario". How can I implement a button cli ...

The POST request encountered an error with status code 500 while being processed by the Express.js framework in the IncomingMessage

My current challenge involves creating a HTTP request for a CRUD application using JS. The aim is to add a new user account record to the Logins database. However, every time I attempt this request, it results in a 500 error: To test this, I have written ...

Access information from multiple div elements using JavaScript data-attributes

Having trouble retrieving data-attribute values from multiple divs with the same class when clicked. The goal is to display the data value of the clicked div. function playSound(e) { const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`) ...

Transferring data from an Angular 2 component to a service

I am trying to pass data from an Angular component to a service and utilize the service's methods to manipulate it. Here is an example: class SomeComponent { public info: Array<any> = MyData; constructor(private myService: TablePag ...

Express is causing an issue with the AngularJS loading process

When I view the index.html file in a browser, everything works fine. However, when I try to run it on a local server using Express, it doesn't work as expected. Server.js const express = require('express'); const app = express(); app.get ...

Difficulty arises when transferring files in Node.js from one directory to another

Attempting to use node.js to transfer files from the currentFolder(root of project)/node_modules/mime/ to currentFolder(root of project)/files/, encountering an error: events.js:85 throw er; // Unhandled 'error' event ^ Error: ...

The suspense fallback function seems to be missing in NextJS 13

I'm in the process of creating an application to demonstrate the functionality of Suspense in Nextjs 13. However, I'm encountering an issue where the Suspense fallback is not appearing during loading. Below is the code for page.js import React, ...

What is the best way to fill radio buttons within a form that is being displayed as a string in PHP?

Looking for assistance with a PHP script that receives data from jQuery through AJAX and then executes a query to retrieve information from MySQL. Once the data is retrieved, I aim to populate a series of radio buttons within a form with this data. The for ...

Changing the li tag by clicking on it is a simple task that can be easily

Whenever I click on a tag, I want the li class to change to "active" and open a new page with the corresponding tag as active. For example, if I click on the Overview tag, the new page should open with the li tag as active. I have attempted to write some c ...

What methods can we employ to prevent the GraphQL query from being triggered with every keystroke when using React?

Recently, I received a new task that requires me to implement input value debouncing to prevent backend requests on every keystroke. Additionally, I need to establish an internal useState for CollectionsAutocomplete, which is connected to the generalQuery ...

Encountering an issue while attempting to run a Node.js server on a Mac, receiving the error message "no appropriate image located."

unknown406c8f2d5ecb:proves airrider3$ node tronServer.js [Error: dlopen(/Users/airrider3/Documents/proves/node_modules/now/node_modules/node-proxy/build/Release/nodeproxy.node, 1): no suitable image found. Did find: /Users/airrider3/Documents/proves/n ...

Locate the parent element using a unique child element, then interact with a different child element

Can you help me come up with the correct xpath selector for this specific element? The element only has a unique href. Is it possible to locate the element by searching for the text iphone X within the href="#">iphone X and also checking for its paren ...

Struggling to map JSON data (received from WCFRest) onto an HTML table

After creating a WCFRestful service that populates data in JSON format as shown below: {"GetEmployeesJSONResult":"[{\"Name\":\"Sumanth\",\"Id\":101,\"Salary\":5000},{\"Name\":\"Sumanth\",\"I ...

Looking for an Angular Material component that displays a list of attributes?

I am trying to create a dynamic list of properties in Angular using Material Design that adjusts for different screen sizes. For example, something similar to this design: https://i.stack.imgur.com/EUsmV.png If the screen size decreases, the labels shou ...

Updating a child component within a Modal: A step-by-step guide

I am using a global Modal component: export const ModalProvider = ({ children }: { children: React.ReactNode }) => { const [isModalOpen, setIsModalOpen] = React.useState(false); const [config, setConfig] = React.useState<ModalConfig | nu ...

How to Use jQuery Post Method to Submit a Form Without Redirecting

I am looking to enhance the user experience of my form by preventing it from reloading upon submission. Specifically, I want to trigger the call to index.php when the submit button named "delete-image" is clicked in the scenario outlined below. It's i ...

Angular EventEmitter coupled with Callbacks

In order to create a custom button component for my angular application and implement a method for click functionality, I have the following code snippet: export class MyButtonComponent { @Input() active: boolean = false; @Output() btnClick: EventEmit ...

VueJS failing to pass parent data to child component

I'm fairly new to Vue Framework and I'm trying to figure out how to update a child component based on changes in the parent component's attributes. In the code snippet below, I've created a component that displays a greeting message bas ...