Show button once modal has been closed

I have a 'start' button that triggers a modal window with an embedded video. Once the user closes the modal, I want to show a 'redeem' button after a delay of 6 seconds.

HTML:

<a id="video-start" onclick="openVideoModal()"><img src="images/playbutton.png"></a>
<div id="modal_video" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<iframe width="560" height="315" src="https://www.youtube.com/embed/O_GQbO7Tthg" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>

<button id="redeem" class="claim hide">Redeem</button></div>

CSS:

.modal_video {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}

.modal-content {
background-color: #ffffff;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 40%;
font-family: 'Rubik', sans-serif;
}

.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}

.claim {
display: none;
}

.modal-content iframe{
 margin: 0 auto;
 display: block;
 }

Javascript:

function openVideoModal() {
document.getElementById('modal_video').style.display = "block";
}

function showRedeemButton() {
var redeemBtn = document.getElementById("redeem");
if (redeemBtn.classList.contains("hide")) {
redeemBtn.classList.remove("hide");
} else {
redeemBtn.classList.add("hide");
}
}

document.querySelector(".close").onclick = function() {
document.getElementById('modal_video').style.display = "none";
setTimeout(showRedeemButton, 6000);
};

window.onclick = function(event) {
if(event.target == document.getElementById('modal_video')) {
document.getElementById('modal_video').style.display = "none";
showRedeemButton();
}
}

The functionality works until I close the video modal; the 'redeem' button does not appear.

I've attempted removing the timeout and directly calling the function, but it still doesn't show up. I'm unsure of what's causing this issue, so I'm at a loss for other solutions to try.

Answer №1

It seems like your problem arises from CSS overriding it due to the presence of the className which styles it as display:none. To resolve this, simply remove the className when you want to display it, and add it back when you want to hide it:

//Remove class to display
document.getElementById("claim").classList.remove("claim");

//Add class to hide
document.getElementById("claim").classList.add("claim");

To adjust your function accordingly:

function showClaimButton() {
     var x = document.getElementById("claim");
     if (x.classList.contains("claim");) {
           //Remove class to display
           x.classList.remove("claim");
     } else {
           //Add class to hide
           x.classList.add("claim");
     }
}

Note that in your CSS, there is:

.claim {
   display: none;
}

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

Challenges with Selenium Web Scraping

I'm currently in the process of creating a web scraper that extracts data from the Beatport top 100 chart. However, I've encountered an issue where some items are successfully located while others result in errors. def scrape_beatport(): user ...

When running the command "npx create-next-app@latest --ts," be aware that there are 3 high severity vulnerabilities present. One of the vulnerabilities is that "node-fetch

Just set up a fresh project with Next.js and TypeScript by following the documentation using npx create-next-app@latest --ts. Encountering multiple high severity vulnerabilities despite running npm audit fix --force, which actually adds more vulnerabiliti ...

Is it possible to include a scroll bar at the top of an overflow-x <div> in addition to or instead of the bottom?

Can the scroll bar be positioned at the top of a table instead of just the bottom? <div style="overflow-x: auto;"> <table> ... ... </table> </div> I am looking for a way to have the scroll bar appear at the top of my t ...

Guide to utilizing Bootstrap v4 SCSS edition in a Bower project

Recently, I have been using the SASS/SCSS version of Bootstrap #3.3.6 but I just found out that they released version 4. While there is a lot of information on how to use Bootstrap v4 (non SCSS) in projects, I'm having trouble finding resources on ho ...

Transitioning images while hovering over a different element

Need some inspiration for a school project? I'm stuck on how to create a smooth image fade effect in CSS when hovering over another element (like an anchor link) on the same page. I've been attempting to use the :target and not(:target) selector ...

What is the best way to retrieve the results of an indexedDb request beyond the limitations of its callback function?

I am working on a form that has an input box which I want to auto-complete with values from an IndexedDb objectStore. Currently, it is functioning with two overlapping input boxes, using a simple array. However, I am looking to make it work with the values ...

Fade out a component in Material UI/React by setting a timeout in the parent's useEffect hook for when it unmounts

Incorporating a fade out transition into my child component, <Welcome />, using Material UI's Fade component is my current goal. This transition should be triggered by two specific conditions: The timeout set in the useEffect function expires. ...

Objects of equal nature combine and sift through

I am looking to categorize objects based on their status ID and also retrieve data and CSR counts for each item. Each StatusName has multiple items: [ { "StatusId": 2, "StatusName": "ordered", " ...

Using TypeScript to define callback functions within the Cordova.exec method

I'm encountering an issue with the TypeScript definition for Cordova. The codrova.d.ts file doesn't allow for any function arguments in the success-callback and error-callback. To better illustrate my problem, here's a small example: Here ...

Attempting to toggle the visibility of div elements based on radio button selections

I'm currently working on a script that will dynamically show and hide different div elements based on the radio button selection made by users. The jQuery library is loading correctly, as I have tested it with an alert message upon page load. Si ...

Tips for transferring the ngRepeat "template" to an ngDirective with transclude functionality

Example: http://plnkr.co/edit/TiH96FCgOGnXV0suFyJA?p=preview In my ng-directive named myDirective, I have a list of li tags generated using ng-repeat within the directive template. My goal is to define the content of the li tag as part of the myDirective ...

How can I allow users to select multiple files with just one input?

Currently, I am able to retrieve a single file from a single input using the following code: $scope.$on("fileSelected", function (event, args) { $scope.$apply(function () { $scope.files.push(args.file); ...

The jQuery newsfeed is powered by the $.each() method

I'm having trouble setting up a newsfeed on my website. It's supposed to display all the current news and exclude any expired ones. I have a webpage where I can add news, so the JSON data is constantly changing. Here's an example of the PHP ...

What is the best way to parse a JSON file and create a dynamic webpage using jQuery with the data from the

As someone who is new to working with Node.js and JSON, I am encountering some issues when trying to extract data from a JSON file. Below is the code that I have written: 'use strict'; const fs = require('fs'); let questsRawData = fs ...

Achieving vertical alignment and stretching of subchild within a flexbox element

I am in the process of creating a mobile navigation menu using Flexbox. It will be a vertical menu that occupies 100% of the available height, with the navigation items evenly spaced and taking up the entire height. The structure I am using is ul>li> ...

Is there a way to modify the state of my spans by utilizing onMouseHover functionality?

I am currently updating the state of my span by using document.getElementById('heart').innerHTML = 'favorite'; Do you have a more efficient method for achieving this? If so, please share your solution with me. Below is my code snippet. ...

Issue with jQuery's addClass() function not functioning properly on Internet Explorer versions 8, 9, and possibly others as well

Here is some basic HTML code: <div class="stuff-choice"> <div class="item a"> <label class="signup-checkbox"> <input type="checkbox" value="a" name="stuff[a][]" id="stuff_choice_" class="things"> <strong>A&l ...

Using socket.io and express for real-time communication with WebSockets

I'm currently working on implementing socket.io with express and I utilized the express generator. However, I am facing an issue where I cannot see any logs in the console. Prior to writing this, I followed the highly upvoted solution provided by G ...

Text that appears when you hover over specific locations within one image

https://i.sstatic.net/G1uWk.png I need assistance in creating a feature where users can see short descriptions of individuals in a photo when hovering over them (not like a tooltip). I attempted to use an area map but encountered difficulties in implement ...

Hide and reveal images on hover by using multiple images or links on a single webpage

Despite my efforts, I haven't been able to find exactly what I'm looking for. My current setup involves an image/content slider powered by Awkward Showcase. Within each slide, I want to incorporate a mouse-in/mouse-out effect that switches and hi ...