JavaScript popup is no more visible on the webpage

Recently, I implemented a pop-up on my website that used cookies to prevent it from appearing every time a user visited a page. However, after making this change, the pop-up stopped showing altogether. Despite my best efforts in testing, researching, and seeking help, I have come to the realization that my understanding of the issue is lacking.

If anyone can offer insight into why the pop-up is not functioning as intended and provide a solution, I would greatly appreciate it.

<div id='popup' style="display:none">
        <div class='cnt223'>
            <h1>Important Notice</h1>
            <p>
                Test!
                <br />
                <br />
                <a href='' class='close' style="color:green">OK</a>
                <a href='' class='goBack' style="color:red">KO</a>
            </p>
        </div>
    </div>
    <script>
        function setCookie(cname, cvalue) {
            window.document.cookie = cname + "=" + cvalue;
        }

        function getCookie(cname) {
            var ca = decodeURIComponent(document.cookie).split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i].trim().split('=');
                if (cname == c[0] && c.length > 1) {
                    return c[1];
                }
            }
            return "";
        }

        function checkCookie() {
            if (getCookie("ageverification") == "") {
                $('#popup').show();
                $('#popup a.close').click(function ( event ) {
                    event.preventDefault();
                    $('#popup').hide();
                    setCookie("ageverification", 'true');
                });
                $('#popup a.goBack').click(function ( event ) {
                    event.preventDefault();
                    goBack();
                });
            } else {
                return null;
            }
        }

        function goBack() {
            window.history.go(-2);
        }
        checkCookie();

CSS "This is just on the same HTML page for now"

<style type="text/css">
    #overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: #000;
        filter:alpha(opacity=70);
        -moz-opacity:0.7;
        -khtml-opacity: 0.7;
        opacity: 0.7;
        z-index: 100;
        display: none;
    }
    .cnt223 a{
        text-decoration: none;
    }
    .popup{
        width: 100%;
        margin: 0 auto;
        display: none;
        position: fixed;
        z-index: 101;
    }
    .cnt223{
        min-width: 600px;
        width: 600px;
        min-height: 150px;
        margin: 100px auto;
        background: #f3f3f3;
        position: relative;
        z-index: 103;
        padding: 15px 35px;
        border-radius: 5px;
        box-shadow: 0 2px 5px #000;
    }
    .cnt223 p{
        clear: both;
        color: #555555;
        /* text-align: justify; */
        font-size: 20px;
        font-family: sans-serif;
    }
    .cnt223 p a{
        color: #d91900;
        font-weight: bold;
    }
    .cnt223 .x{
        float: right;
        height: 35px;
        left: 22px;
        position: relative;
        top: -25px;
        width: 34px;
    }
    .cnt223 .x:hover{
        cursor: pointer;
    }
</style>

Answer №1

Can you confirm if the element identified by id "popup" is nested inside of (a child of) the element with id "overlay"? If it is, then the element with id "overlay" is set to display:none; which means that while the popup may be visible, its parent is hidden. You can try updating the code like this:

$('#popup, #overlay').show();

Another issue could be that the JavaScript is running before the browser has fully loaded the element with id "popup" into its DOM. In that case, you can try changing the code from:

checkCookie();

to:

$(function () { checkCookie(); });

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

Puppeteer App Error: An error has been detected on the client side

I am facing an issue using Puppeteer with NEXT.JS while attempting to capture a screenshot. Everything runs smoothly on localhost, but in production, the captured image comes back with the following error message: Application error - a client-side exceptio ...

Link the click counter to individual products

Currently utilizing Wordpress I have successfully implemented a jQuery click counter. However, I am now looking to integrate this code into the div of the quick view button as the quick view button do not currently track any view counts. How can I effici ...

A technique in JavaScript that allows for assigning object property values using an external variable

I need to clarify my situation with a code example const faultLine = new google.maps.Polyline({ paths: [ new google.maps.LatLng(49.95, -128.1), new google.maps.LatLng(46.26, -126.3), new google.maps.LatLng(40.3, -125.4) ] }); ...

Don't forget to include a file upload feature when submitting a form

I'm working with codeigniter and jquery to develop a form that includes text input fields as well as a single file upload option. I'm aiming for the functionality where even if the form validation fails, the uploaded image will still be visible t ...

Revealing information about a photo when hovering over it

I am currently working on a project where I need to display images from a database in two columns. My goal is to have additional details about each image, such as the country and year it was taken, appear when I hover over them. A good example of what I&ap ...

Encountering the 404 Not Found error when trying to fetch the Next.js API Route from the app

Currently facing difficulties with the routing in Next.js 13's app. Every time I attempt to access it, for instance via Postman, I keep getting a 404 Not Found error. This is my file structure: https://i.stack.imgur.com/ZWrlb.png An example of one ...

Is bower install failing to detect a local npm package?

After running bower install, I encountered the following error message: $ bower install module.js:340 throw err; ^ Error: Cannot find module 'minimist' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._l ...

How to Keep Button Highlighted After Clicking

I've experimented with various methods like using :active, :focus, adding a class, and modifying CSS rules through jQuery to maintain the button highlight, but none of them have been successful. Please take a look at my code and point out any mistakes ...

I am encountering errors when running NPM start

After setting up my webpack, I encountered an error in the terminal when attempting to run the code npm start. The specific error message was related to a module not being found. Can someone please assist me with resolving this issue? > <a href="/c ...

Showing an image stored in an array using JavaScript

This script is designed to pull images from a specific location on an HTML page. images = new Array(); images[0] = new Image(); images[0].src = "images/kate.jpg"; images[1] = new Image(); images[1].src = "images/mila.jpg"; document.write(images[0]); I&a ...

Connect select with an array of objects and showcase information when an item is chosen from the dropdown menu

I have an array $scope.items= [ { name: "Jon Snow", email: "jon@example.com", password: "WinterIsComing" }, { name: "Daenerys Targaryen", email: "daenerys@example.com", password: "FireAndBlood" } ]; Now, I am trying to show the email value in a dropdown ...

.encounter issue with loading Internet Explorer

Currently, I am utilizing the .load method to load some data into a div. It is functioning properly overall, but when attempting to specify and load a particular ID from the HTML, Internet Explorer fails to load anything. For example: $('div.myDiv&a ...

Tips on how to retain data from ajax requests when navigating between pages

Background Information In my web application, there is a search page with 3 dropdown boxes that are filled via ajax. The first box contains default locations upon loading the page. When a location is selected, a second dropdown appears with buildings from ...

What steps are needed to successfully enable the callback function within the addFilter method from @wordpress/hooks while customizing the tables in WooCommerce analytics reports?

I've been diving into customizing Analytics reports tables for clients on our WooCommerce platform. I followed a guide at this link, but encountered an issue with the JavaScript file. After adding the filter at the end of the file as instructed, noth ...

Remove any objects from the array that have empty values when filtered

I am facing a challenge with filtering objects in an array. Each object contains a title and rows, where the rows also have a risk value (like P1, P2, P3, etc.). My goal is to extract only the rows that have a risk equal to P1 while skipping any objects th ...

Exploring ways to personalize Angular UI Bootstrap tabs to match the styling of Angular Material tabs

Currently, I am utilizing Angular UI Bootstrap in my project. <html ng-app="ui.bootstrap.demo"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script> <script src="//ajax.googleapis.co ...

What is the best way to select and style individual HTML elements using CSS?

Having trouble editing a Validations Form in Ionic 4 with CSS. It seems that only the form elements are targeted after clicking on the form group. Attached below are the form states before and after click. I'm unable to style the form elements before ...

nodemon keeps attempting to restart the server after making changes to files, but the updates are not being reflected

I've been using the nodemon package, but I'm experiencing issues with it not restarting the server properly. Instead of showing "server running" after making changes like in tutorials, all it displays is "restarting due to changes". This also res ...

Reposition the span element to the right of the div tag

I need help adjusting the positioning of the elements in this HTML code. How can I move the span element with the image to the right of the div tag? Here is the code snippet: <div style='width:600px;padding-top: 2px;padding-bottom: 1px'& ...

Trouble with the drop-down menu displaying "string:2" in an AngularJS application

Currently, I am utilizing AngularJS ng-model to choose the value from a drop-down menu. Additionally, I am implementing datatable for organizing the columns. <select id="{{user.id}}" ng-model="user.commit" name="options" ng-change="update_commit_level ...