Stop modal content from automatically opening

Is there a way to prevent the content inside from opening before it is clicked? Every time I try to create a modal or dropdown list menu, the content always opens automatically before being clicked. Why does this happen?

var modal = document.getElementById('modal-wrap');
var open = document.getElementById('modal-open');
var close = document.getElementById('modal-close');


open.onclick = function() {
    modal.style.display = "block";
};


close.onclick = function() {
    modal.style.display = "none";
};

window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
.modal-wrap {
    display: none;
    position: fixed;
    z-index: 99;
    padding-top: 100px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    opacity: 40%;
    background-color: rgb(0,0,0);
    background-color: rgba(0,0,0,0.4); 
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

.modal-close {
    float: right;
    padding: 5px;
    border-radius: 5px;
    font-weight: bold;
}

.modal-close:hover,
.modal-close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
<button id="modal-open">Open</button>
      <div id="modal-wrap" class="modal-wrap">
        <div class="modal-content">
          <button class="modal-close" id="modal-close">Close</button>
          <p>Edit the data </p>
              <div class="form-group">
              <label for="name">Name</label>
              <input id="name" placeholder="Input your Name"> 
              </div>
  
        </div> 

      </div>

Furthermore, this code works as expected in snippets or JS Bin. However, why does its appearance change by default when running it on my localhost project? here

Answer №1

All that comes to mind is the possibility that your JavaScript file may not be properly linked?

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 not loading all the videos on a single page

Currently, I am working on a project that involves loading multiple videos on a single web page. The code snippet I am using looks like this: <div class="video_content left"> <span style="font-weight:bold">1</span> <video wi ...

Tips for implementing cloudinary jquery to showcase a positive outcome notification

I've been utilizing the cloudinary Upload widget to upload multiple images successfully. However, I'm encountering an issue where I can't display a success message after the process is completed. Below is the JavaScript code I am using for u ...

Is there a way to transform NextJS typescript files into an intermediate machine-readable format without having to build the entire project?

I need to deliver a Next.js project to my client, but I want to modify the TypeScript files so they are not easily readable by humans. The client will then build and deploy these files to their production environment. How can I achieve this? In summary, C ...

Error in Firefox when converting a string to a date in JavaScript using the format mm-dd-yyyy

Hi, I am encountering an issue with converting a string in the format mm-dd-yyyy into a date object. While it works perfectly fine in Internet Explorer and Chrome, it does not work in Firefox as it returns an invalid date at times. I have also tried using ...

Bootstrap - extra spacing

Utilizing bootstrap, I have implemented two div elements in my HTML code: <div class="container"> <div class="col-12 circle lg-circle"> <div class="col-12 circle sm-circle"> </div> </div> </div> The corresp ...

Utilizing Node.js ORM2 callback functions with custom parameters

Currently, I am developing models using a for loop: for (var j = 0; j < data.length; j++) { models.MyModel1.create({ name : data[j].name }, function(err, model){ if (err) { throw err } ...

Troubleshooting: Issues with Contenteditable div functionality in Angular 2

When HTML text stored on the server is bound to a contenteditable div, it is not processed or rendered as expected. Instead, it is displayed in its raw form. For example, the following HTML text from the server is shown as plain text rather than rendered ...

The element is implicitly classified as an 'any' type due to the index expression not being of type 'number'

Encountering a specific error, I am aware of what the code signifies but unsure about the correct interface format: An error is occurring due to an 'any' type being implicitly assigned as the index expression is not of type 'number'. ...

A component with angular features will not persist

I have a menu component: <nav class="mxmls-mobile-nav"> <button class="mobile-menu-btn visible-xs visible-sm " ng-click="asideVm.open = false"> <i class="ion-android-close"></i> </button> </nav> <a class ...

Vue 3 has officially deprecated the use of ::v-deep as a combinator. Going forward, please utilize ::v-deep(<inner-selector>) instead

Recently, an error message has been popping up in Vue 3 regarding the use of ::v-deep. The warning states that using ::v-deep as a combinator is deprecated. Instead, it recommends using ::v-deep(<inner-selector>) Here is an example of the CSS ...

The functionality of Angular's $window.scrollTo() seems to be malfunctioning

After successfully finding a specific element on my Angular app's page, I am attempting to scroll to it. However, despite trying both $window.scrollTo() and window.scrollTo(), the scrolling action is not being executed as expected. My console does log ...

Utilize Ajax.ActionLink on a DIV by incorporating data from the Model

Although there are similar questions on this topic already, they do not address the specific issue of using values from the model as arguments for the controller. Make DIV containing AJAX ActionLink clickable Div as Ajax.ActionLink Take a look at the fo ...

Make sure to have only one description per file enforced

The Scenario: In our extensive test codebase utilizing Protractor+Jasmine, we are encountering an issue where some test/spec files contain multiple describe blocks. This has caused issues during debugging, as using fdescribe/fit to run tests individually ...

What are some ways to utilize v-on="$listeners" besides just for @click events?

My Button.vue component has a specific structure. I am utilizing v-on="$listeners" to transfer all listeners to the <a> element. <template> <a v-bind="$attrs" v-on="$listeners" class= ...

Generate a randomly structured 2D array called "Array" using JavaScript

Can anyone help me with extracting a random array from a 2D named array? I've tried several solutions but none of them seem to work. var sites = []; sites['apple'] = [ 'green' , 'red' , 'blue' ]; sites['o ...

Adjusting the content and style of a div element upon clicking, and restoring the original settings when clicked once more

There is a div with the id #increase-text-weight that displays the text "INCREASE TEXT WEIGHT". Upon clicking on it, the font weight of another div with the id #post-content should be changed to font-weight: 500 and the text inside #increase-text-weight s ...

Why isn't the variable changing when exported to another file in Node.js?

My issue revolves around handling two arrays of objects in server.js, which I export using module.exports for use in another file called scores.js. The problem arises when I attempt to reset these arrays for a new game, as some data does not update correct ...

Create a simulated API in Angular by utilizing JasonPlaceholder to retrieve information upon clicking a button

I am currently developing a dummy API using jsonplaceholder. I have managed to retrieve all posts after clicking a button, but now I want to display the user ID and title by default on page load. Additionally, when clicking on a post's title, I would ...

Having trouble incorporating Mesh instances into an array

I'm attempting to create multiple copies of a mesh randomly positioned throughout my THREE.Js scene. To achieve this, I have utilized the clone() method within a for loop. The console displays an array showcasing the clones I generated, however, when ...

The function angular.factory does not exist

Hey there! I am encountering an error in the title related to my factory. Any suggestions on how I can resolve this issue? (function (angular,namespace) { var marketplace = namespace.require('private.marketplace'); angular.factory(&apo ...