I am struggling to get the pop-up to close using the current code. I suspect that the issue might be related to the variable I was previously using in WordPress. I have made changes but the pop-up

While delving deeper into the realm of Javascript, I encountered a stumbling block with a single popup intended for the main page of a WordPress website I am constructing. Despite my attempts to modify the code's variables, they seem unyielding. Surprisingly, the console.log('modal initiated') function works flawlessly, yet the others remain lifeless.

    <html>
<div class="popup-body_1" id="popup-show_1" style="">
      <div class="popup-wrapper_1">
        <span class="popup-x_1" id="popup-x_1">&times;</span>
        
        <div class="popup-image_1 popup-image-custom_1">
            <img class="product-image_1" src="https://mlservice.blob.core.windows.net/website/UploadBestanden/tn/cc675fd2-f457-4986-af22-2810ce7a3167-1440-420.jpg">
        </div>
        <div class="sign-up_1"> 
          <h2 class="content-cont1_1" ><span class="popup-title_1">Nieuw hier ? </span></h2>
            <p><span class="popup-subtitle_1">laat me <strong>weten</strong><br class="popup-pc_1"> wat ben jij?</span></p>
          <div class="popup-content_1">
 
         <div class="tooltip">   
            <button class="submit-shop_2" href="https://www.werkenbijml.nl/job-dashboard">Ben jij enn werknemer?</button>
         </div>
         <span>
         </span>
         <div>
             <button class="submit-shop_1 custom-btn_1 content-cont3_1" href="https://www.ml-service.nl/">Ben jij een werkgever?</button>
         </div>
          </div>
        </div>
      </div>
    </div>
    </html>
    <style>
.popup-blackout_1{
  position: fixed;
  background: #000;
  display: block;
  opacity: .0;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 200;
}

.popup-body_1 {
  width: 75%;
  max-width: 800px;
  position: fixed;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);
  margin: 0 auto;
  background: #e0e6eb;
  border-radius: 20px;
  z-index: 250;
}
.product-image_1{
  border-top-left-radius: 25px;
  border-bottom-left-radius:25px;
}
.popup-content_1{
  margin-top:15%;
}
.popup-wrapper_1 {
  display: flex;
...
  
.google-play-badge{
    color:red;

}
@media(min-width:768px){
 
}
.custom-container{
    display:flex;
}


/*Tooltip*/
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
  top: -5px;
  left: 105%;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
    </style>
    <script>

var modalbanner = document.getElementById("popup-show_1");

var spanbanner = document.getElementsByClassName("popup-x_1")[0];

setTimeout(function () {
    modalbanner.style.display = "block";
    console.log("modal initiated");
}, 10000);

spanbanner.onclick = function () {
    modalbanner.style.display = "none";
    console.log("closed banner");
}

spanbanner.onclick = function (event) {
    if (event.target == modalbanner) {
        modalbanner.style.display = "closed banner";
    }
}
    </script>

Answer №1

  • The issue with the modal not closing, as pistevw pointed out, is due to the second onclick() function.
  • If the button is located within a hidden block, it will be inaccessible after the functions have executed. Move the button outside of the block.
  • For toggling styles, you can utilize css classList toggle or create a global variable and toggle it accordingly.
var modal_opened = true;
spanbanner.onclick = () => {
  modalbanner.style.display = modal_open?'none':'block';
  modal_open=!modal_open
  console.log((modal_open?'opened':'closed')+' banner');
};

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

Chrome DevTools automatically translates all HEX color codes into their corresponding RGB values

Chrome DevTools now automatically converts all HEX colors to RGB values, even if the color is set in CSS or using DevTools. Is there a way to prevent this conversion? I know about the method of holding down Shift + clicking the color icon to convert color ...

Ways to center Bootstrap panel in the middle of a webpage

Is there a way to center this entire panel on the web page? I could use some guidance with this. Does anyone have recommendations for a good book to learn Bootstrap design? <div class="panel panel-default" style="max-width:500px;margin-left:auto;margi ...

I am looking to incorporate a feature in my form that allows for multiple file uploads and displaying them

Currently, I have a single file upload input field in my form and it works perfectly fine. However, I am looking to add multiple file inputs to the form as well. I have attempted various methods to integrate the code for multiple file uploads into my form, ...

"After executing a loop in JavaScript using jquery.ajax, the success function does not perform

Having trouble passing values from a PHP file to another function in Javascript. Even after a successful FOR LOOP, nothing seems to work within the SUCCESS block. Any suggestions? url1 = 'http://localhost:81/Dashboard/admin/inc/dashboard.php'; $ ...

The Hidden Power of jQuery: Unleashing the Full Potential of .text()

I'm trying to make two values equal, but it's not working... var rowID = $("#@idSelectObjectGuid").val(); $($(".ls-grid-body tr").children("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="240a64524770454648410a74564d ...

Learn how to personalize your Material UI icon by incorporating a plus symbol

Is it possible to add a plus sign to material ui icons? I currently have the following icon: import ApartmentIcon from '@mui/icons-material/Apartment'; I would like to add a plus sign to this icon, similar to this example: I have attempted to ...

Achieving responsive masonry layout with Bootstrap 4

I'm attempting to implement the bootstrap 4 masonry effect on my website, but I'm facing issues with card responsiveness. The page is very basic without any special effects. While the page works well when resizing the browser window, it doesn&ap ...

Dynamic font size that adjusts as you change the window dimensions

Is there a way to adjust the font size in HTML so that when I resize the window, the text size adjusts accordingly? It's like setting a percentage for the text based on the size of the container it is in. Let me provide an example of what I have in m ...

Activate or deactivate a text box within a table based on the checkbox's status

I am seeking assistance with jQuery to enable or disable a textbox within a table when a checkbox is checked. Below is the code snippet from my edit.cshtml file. <table id="scDetails" class="dataTable"> <thead> & ...

Issue with by.cssContainingText function not performing as intended

I have a container that I want to be able to click on. Here's how it looks: <div class="CG-Item CG-B-Left ng-binding" ng-bind="SPL.showTitleText">My New SPL</div> So I am trying to use this code to click on it: element(by.cssContainingT ...

Ways to display success message following JavaScript validation

I've been working on creating a form that displays a success message after JavaScript validation checks are successful. To show the success message, I'm utilizing Bootstrap alert. I split my code into two files - one for common validation functio ...

Create a specialized angular controller

Is there a way to create a custom controller programmatically while preserving scope inheritance? I am looking to achieve something similar to this: var controller = 'myCtrl'; var html = '<p>{{value}}</p>'; var validScope= ...

Looking to streamline your design? Find out how to translate multiple elements to the same position seamlessly

Greetings! This is my debut post on this platform. I am currently engrossed in a project that has presented me with a challenge, and I'm reaching out to seek your insights on a potential solution. Here's the scenario: I have a parent div containi ...

Updating the textarea with Ajax without the need for a button click or refreshing the

I need to implement a feature where a textarea will automatically update the database without requiring the user to click on any buttons or refresh the page. The idea is that after a keyup event, there should be a 2-second countdown timer. If no additional ...

What is the best way to identify a particular subtype of HTMLElement based on its tag name and then save that element within another one?

I have a function that generates a node and returns it. Here is an example implementation: addElement: function ({ parentNode, elementName, tagName, }) { // Creates and appends the new node. parentNode[elementName] = document.createEl ...

What are the signs that indicate a potential code breakage following an upgrade of the JavaScript library in use?

Imagine you have incorporated multiple JavaScript libraries into your website. Your code interacts with various APIs, but occasionally, after an update, one of the APIs changes and causes your code to break without any prior notice. What steps can you tak ...

"Textarea auto-resizing feature causes an excessive number of unnecessary lines to be added

I have a textarea that is coded with jQuery to limit the characters to 11 per line and automatically resize based on the number of lines. However, when users click 'Enter' to add a new line, it adds multiple extra lines instead of just one. This ...

`In the event that a series of criteria is unfulfilled in a JavaScript forEach() loop`

My IntersectionObserver utilizes a forEach method to invoke certain functions when a condition is met for each item in an array: const sections = document.querySelectorAll("section") function removeHighlight(id) { someElementArray[id].cl ...

How can I position text below a ticked checkbox?

Having an issue with my HTML and jQuery code. Everything is working fine, but when I click on a checkbox, the text "FINISHED" appears below all checkboxes instead of just the one I clicked on. This is my html code: $('.label__checkbox').cli ...

What are some ways to ensure that the promise from postgres is fulfilled before moving forward with my code execution?

I am currently developing a Node-js application that requires retrieving information from the database before making another database call. However, I am facing an issue where the first check is not always resolved before proceeding to the next step. I hav ...