Tips for implementing a CSS style alteration upon clicking a button in a separate HTML page

I created JavaScript quizzes for my users to complete. Once they click the finished button at the end of the quiz, I want to highlight the box on the home page with a green outline to indicate completion. The complete button is located on the challenge1.html page, and I aim to outline the item in the grid on home.html. Can someone provide guidance on how to achieve this?

Files: home.html, challenge1.html, home.css, challenge1.css, and quiz.js

home.html

         <div class="grid-container">
             <a href="challenge1.html"><div class="grid-item item1">1. Discover HTML Basics and Tags</div></a>
             <a href="challenge2.html"><div class="grid-item item2">2. Styling HTML with Tags</div></a>
             <a href="challenge3.html" class="grid-item item3"><div>3. Creating Links and Images</div></a>
             <a href="challenge4.html"><div class="grid-item item4">4. Building Features</div></a>
             <a href="challenge5.html"><div class="grid-item item5">5. Building Lists</div></a>
         </div>

challenge1.html

        <div class="container">
              <div id="question-container" class="hide">
                <div id="question">Question</div>
                <div id="answer-buttons" class="btn-grid">
                  <button class="btn">Answer 1</button>
                  <button class="btn">Answer 2</button>
                  <button class="btn">Answer 3</button>
                  <button class="btn">Answer 4</button>
                </div>
              </div>
              <div class="controls">
                <button id="start-btn" class="start-btn btn">Start</button>
                <button id="next-btn" class="next-btn btn hide">Next</button>
                <a href="home.html"><button id="complete-btn" class="complete-btn btn hide">Complete</button></a>
            </div>
        </div>

home.css

.grid-container {
  display: grid;
  margin-top: 30px;
  grid-gap: 10px;
  background-color: #FFFFFF;
  padding: 10px;
}
.grid-container3 {
  display: grid;
  margin-top: 30px;
  grid-gap: 10px;
  background-color: #FFFFFF;
  padding: 10px;
  margin-bottom: 100px;
}
.grid-item {
  background-color: #E26CBA;
  padding: 20px;
  font-size: 20px;
  border-radius: 20px; 
  font-family: 'Poppins', sans-serif;
  color: #3F0068; 
}

.item3 {
  grid-column: 1 / span 2;
  grid-row: 2;
}

challenge.css

*, *::before, *::after {
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}

:root {
  --hue-neutral: 200;
  --hue-wrong: 0;
  --hue-correct: 145;
}

...

quiz.JS

...

Answer №1

In the previous comment, Steve suggested using sessionStorage or localStorage for your needs. For example, after the user finishes the quiz, you can execute the following command:

window.sessionStorage.setItem("challengeCompleted", "true")

Subsequently, in your home.html page, you can include something similar to this:

let challengeCompleted = window.sessionStorage.getItem("challengeCompleted")
if (challengeCompleted !== null && Boolean(challengeCompleted)):
    // Implement your CSS changes here
    let btn = document.getElementById("your-btn-id");
    btn.style["border-color"] = "green";

This is just a rough example. I haven't verified the code, but I quickly wrote it from memory to convey the concept.

Additionally, consider using localStorage if you want the website to always remember the user's progress, or opt for sessionStorage if the progress should reset each time the user revisits the site.

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

Scroll horizontally through the number field in Chrome

I have configured a number input field with the text aligned to the right. Scenario: While testing, I discovered that selecting the entire text or using the middle mouse button to scroll within the input field allows for a slight leftward scrolling of ab ...

The property 'matMenuTrigger' cannot be attached to 'a' because it is not recognized

Trying to implement matMenuTrigger but encountering an error saying "Can't bind to 'matMenuTrigger' since it isn't a known property of 'a'". Any assistance would be greatly appreciated. ...

Using jQuery to Extract HTML Content from a JSON Object

I'm completely lost on what I'm doing incorrectly, but the JSON string I have looks like this: jsonp443489({"content":"<!DOCTYPE html><html><head><title>Title</title></head><body><p>Hello World< ...

The sub-menu options are constantly shifting... How can I keep them in place?

Here we go again... I'm having trouble with my sub-menu elements moving when I hover over them. I've searched for a solution but haven't found anything helpful. The previous advice I received about matching padding and adding transparent bo ...

Merge the xAxis functionality with Highcharts

My issue involves a chart generated by highcharts.js. The problem arises with a line chart consisting of 5 values (5 points), each displayed on the xAxis as follows: from value 1 to value 2: 0, 0.25, 0.5, 0.75, 1. I am looking to modify this display and re ...

How to align text to the right with ellipsis and button in a ReactJS component

In a specific scenario, I need to display a button on the right corner of the header. The selected filter value should appear next to the filter button like this: | Between 01/23/2018 and 07/30/2018 {button}| As the user changes the screen size, I want to ...

Unable to get font-face to function properly on IE versions 7 and 8

I'm having trouble getting the font-face to work properly on both IE7 and IE8. This is the code snippet I have used: @font-face { font-family: 'DroidSans'; src: url('fonts/DroidSans.eot'); src: url('fonts/DroidSa ...

Getting rid of the <br> tag as well as the linked <span> element

I've been experimenting with creating dynamic forms. My latest project involves a text box, an 'Add' button, and a div. The idea is that whenever a user types something into the text box and clicks the Add button, that value should appear in ...

Using async/await with Axios to send data in Vue.js results in different data being sent compared to using Postman

I am encountering an issue while trying to create data using Vue.js. The backend seems unable to read the data properly and just sends "undefined" to the database. However, when I try to create data using Postman, the backend is able to read the data witho ...

Discover the best way to retrieve attribute values using jQuery

I'm struggling to retrieve the value of the attribute "_last_val" from my input, but I'm having trouble getting it. Here is what I have attempted: demo // Here is the HTML code <form method="post" action="" id="feedback_form"> <inpu ...

Carrying over additions in arrays using only Javascript

I'd like to implement a basic array addition with carryover. Additionally, I need to display the carryover and result values. For instance: e.g var input = [[0,0,9],[0,9,9]]; var carryover = []; var result = []; Thank you! ...

Combine and emphasize several gridview rows into a single highlighted unit

Imagine you have a gridview that looks like this: FAMILY GROUP COLOR =============================================== | | Poodle | Blue ROW1 | DOG | German Shepherd | Red | | Pitbul ...

After sending a GET request in AngularJS, simply scroll down to the bottom of the

Usually, I use something like this: $scope.scrollDown = function(){ $location.hash('bottom'); $anchorScroll(); } While this method works fine in most cases, I've encountered an issue when fetching data for an ng-repeat and trying t ...

Performing math calculations on data inputted through a form in React Native

As a beginner in React Native, I am working on a simple app that consists of two screens: Calculator and Result. The Calculator screen has two input fields that only accept numeric values. Upon pressing the result button, the app should navigate to the Res ...

Display Text Only When Selected - Material-UI

Is there a way to display only the selected tab's text? I came across this code snippet in the MUI documentation that involves showing labels on selection. How can I achieve this effect, maybe by manipulating the state to change the color of the selec ...

What is the best method for navigating and passing data in dynamic routing with NEXT.JS?

In the process of developing my next.js ecommerce app, I am utilizing Firebase to fetch product data. My goal is to have users click on a product and be redirected to a new page displaying the details of that particular product. However, despite using the ...

Design the parent element according to the child elements

I'm currently working on a timeline project and I am facing an issue with combining different border styles for specific event times. The main challenge is to have a solid border for most of the timeline events, except for a few instances that share a ...

Unable to load circles on page refresh with amCharts Maps

I am experiencing an issue with the functionality of my amCharts maps. Whenever I refresh the page, the circles that are supposed to be displayed disappear. However, when I zoom in, the circles reappear. This problem has me puzzled, and I'm not sure ...

Scrollbar becomes inactive following the loading of AJAX content

Having an issue with loading a div using Ajax. The div loads, however the scrollbar within it stops working afterwards. In Main.html, I load content from other HTML files like so: <div id="content1" > </div> The content is loaded as follows: ...

Having trouble with the `npm run dev` command in a Laravel project? You may be encountering a `TypeError: program.parseAsync is not

Recently, I integrated Vue.js into my ongoing Laravel project using npm to delve into front-end development with the framework. Following the installation, the instructions guided me to execute npm run dev in order to visualize the modifications made in . ...