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

Locating a Guild Member using their Alias

I need help locating a GuildMember using their nickname. The nickname is linked to their Roblox name upon joining the server, and I've configured a webhook to transmit a message in a specific channel containing their username and other related details ...

What is the best way to incorporate a new attribute into a particular CSS class?

Just to provide some context, I am relatively new to all of this. Please bear with me. I have a unique CSS class that is specifically assigned to thumbnail images on my Wordpress website. Currently, I am using a script that adds a "Pin it" hover link to a ...

Is there a way to immobilize an object in JavaScript without resorting to Object.freeze()?

Is there a way to freeze the following object without relying on Object.freeze()? Let's find out: const obj = { a:'test', b:'Something' } ...

Alter the color of the text within the `<li>` element when it is clicked on

Here is a list of variables and functions: <ul id="list"> <li id="g_commondata" value="g_commondata.html"> <a onclick="setPictureFileName(document.getElementById('g_commondata').getAttribute('value'))">Variable : ...

Unraveling the complexities of parsing multi-tiered JSON structures

I am struggling with indexing values from a multi-level JSON array. Here is the JSON data in question: { "items": [ { "snippet": { "title": "YouTube Developers Live: Embedded Web Player Customization" } ...

Utilizing jQuery's then() method to display HTML and JSON outputs from printing operations

Currently, I am in the process of mastering jquery deferreds. When working with html on jsfiddle, I receive an object that contains two lines when printed within the then() statement: "success" and the html returned by the ajax request. For instance, upo ...

Retrieve information from the existing URL and utilize it as a parameter in an ajax request

Currently, I am working on a website with only one HTML page. The main functionality involves fetching the URL to extract an ID and then sending it to an API using an AJAX call. Upon success, the data related to the extracted ID is displayed on the page. H ...

Angular displaying undefined for service

I have created a service for uploading images to a server, and I am encountering an issue when calling this service from my controller. The error message indicates that the function 'uploadFileToUrl' is undefined. Below is the code for my servic ...

Send a res.json response and retrieve it using res.render in a different router

Trying to retrieve a JSON from the route "/api/product" and display it using hbs on the "/product" route. The code seems to be working, but is it done correctly? The router in this case is: '/api/product' router.get('/', this.controll ...

Toggling the form's value to true upon displaying the popup

I have developed an HTML page that handles the creation of new users on my website. Once a user is successfully created, I want to display a pop-up message confirming their creation. Although everything works fine, I had to add the attribute "onsubmit= re ...

Array of generic types in Typescript

Here's a method that I have: getFiveObjectsFromArray(array: T[]) { return array.slice(0, 5); } I've been using this method multiple times. Is there a way in TypeScript to pass a generic argument instead of using multiple types? Also, when ...

"Running experiments with Google Ads and Google Analytics scripts results in a blank page being displayed

Currently, I am working on a plain HTML file and conducting tests to ensure that the Google Ads and Analytics scripts are functioning correctly before implementing them on other pages. A colleague who has an AdSense account provided me with the script code ...

Mongoose Alert: Unable to Create Schema Instance

Below is the Schema file that I'm using: const mongoose = require("mongoose"); const ProblemSchema = new mongoose.Schema( { slug: { type: String, required: true, unique: true, }, title: { type: String, ...

What is the best way to target changing elements displayed by *ngIf?

Trying to access a dynamic element generated by ngIf in the code below has proven to be challenging. I attempted two different methods: Using ElementRef and querySelector Component template: `<div class="test" *ngIf="expr"> <a id="b ...

What is the method for sending an axios post request using the application/x-www-form-urlencoded content type?

How can I successfully send an axios post request using application/x-www-form-urlencoded? I am trying to include a refresh token in the request, but currently an empty object is being sent. However, I have verified that the token exists when checking "us ...

AngularJS substitution with regular expressions

Looking to replace specific words in HTML content within <div> and <p> tags upon page load. Utilizing angularJS to achieve this task. This is my current function: var elementsList = e.find('p'); var regex = ('[^<>\& ...

Sending data from jQuery to an AngularJS function is a common task that can be accomplished in

In my Controller, I have a function that saves the ID of an SVG path into an array when a specific part of the image.svg is clicked. $(document).ready(function(){ var arrayCuerpo=[]; $('.SaveBody').on("click", function() { ...

Tips for retrieving data from a Node.js server with a POST request in a React application

I'm currently working on a MERN authentication project, but I've hit a roadblock. Whenever the information is submitted on my register page, it triggers an add user function on the front end. async function addUser(user) { const config = { ...

Unable to substitute a value using the useState hook in React

Whenever I click a key, I attempt to update the value of a variable but it appears not to be working as intended. ↓ The current implementation is not effective and needs improvement import React, { useState, useEffect } from 'react'; const Li ...

SapUI5: Implementing a toggle functionality to display/hide one list item based on another list item's action

UI5 is a versatile framework with numerous possibilities, but sometimes I find myself struggling to implement ideas that would be easier in traditional HTML. Here's the scenario: I want to create a List with ListItems that display cities like Berlin, ...