Why won't my HTML/CSS/JavaScript modal pop up in front of everything else?

Attempting to create my own modal in JSFiddle has been an interesting challenge for me. Once I had something that worked, I tried implementing it on my website. Unfortunately, the modal appears behind other elements on the page. What could be causing this issue? I can provide the index page HTML code if necessary. Here is the link to the popup:

https://jsfiddle.net/o6xf5a6d/18/

Modal:

HTML:

<h2>System</h2>
<button onclick="sitaSeen('https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpovbSsLQJf3qr3czxb49KzgL-KmsjwPKvBmm5D19V5i_rEprP5gVO8v11lZj-gIYbDclRqMA7Zq1S7lOm-0Za6753KmHoxvnQh5y7ZyhWxiRwecKUx0iL1oy6z/60fx60f','M9 Bayonet | Doppler','Battle Scarred',70)">Click</button>
<button id="myBtn">Open Modal</button>
<div id="myModal" class="modal">
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">×</span>
      <h2>Logo</h2>
    </div>
    <div class="modal-body">
      <table class="centered">
        <thead>
          <tr>
            <th data-field="pic"></th>
            <th data-field="id">Item</th>
            <th data-field="name">Conditon</th>
            <th data-field="price">Price</th>
            <th data-field="delete"></th>
          </tr>
        </thead>
          <tbody class="papa">
          </tbody></table>
      <span id="total">Total: $0</span>
      <button class="btn black right">seen</button>
    </div>
  </div>
</div>

JavaScript:

var modal = document.getElementById('myModal');
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
  modal.style.display = "block";
}
span.onclick = function() {
  modal.style.display = "none";
}
var total = 0;

function sitaSeen(img, name, condition, price) {
  $('tbody').append("<tr><td><img src=" + img + "></td><td>" + name + "</td><td>" + condition + "</td><td>$" + price + "</td><td><span>X</span></td></tr>");
  total += price;
  $('#total').empty();
  $('#total').append("Total: $" + total);
}
$('.papa').on('click', 'tr span', function(){
        $(this).closest('tr').remove();
});

CSS + Materialisecss

thead, tbody { display: block; }
.papa{
    overflow-y: scroll;
    max-height: 195px;
}
table {
  box-sizing: border-box;
  border-bottom: 3px solid white;
}
td,
th {
  padding-left: 16px;
  min-width: 140px;
  border: 3px solid white;
  font: 14px/40px;
  text-align: left;
}
td {
  color: white;
}
tr {
  display: block;
}
th {
  color: white;
}

table tbody tr:nth-child(even) {
    background-color: #201f1f;
    box-shadow: inset 0px 0px 25px 2px black;
    border-bottom: 1px solid #545254;
}
table tbody tr:nth-child(odd) {
    background-color: #333333;
    box-shadow: inset 0px 0px 25px 2px black;
    border-bottom: 1px solid #545254;
}
#myModal {
  background-color:#545254;
  color:white;
}

Answer №1

To make an element appear on top of others, utilize the z-index in CSS:

#myElement {
  background-color: #546487;
  color: black;
  position: absolute;
  z-index: 10;
}

Remember to specify the position property for the z-index to take effect.

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

Transform numbers into elements of an array and replace undefined with an empty array

Check out this Plunker example where a filter is implemented to allow select box options to be selected only once: http://plnkr.co/edit/BBqnTlxobUpiYxfhyJuj?p=preview .filter('arrayDiff', function() { return function(array, diff) { console.log ...

How do I connect TypeORM to multiple databases?

I am faced with the challenge of creating tables in two different databases using TypeORM. Each table is associated with a specific database through the use of the @Entity decorator. However, I encounter an error stating that user x does not have write acc ...

Split the string in JavaScript and then count the characters to decrypt

I am currently working on a task that involves splitting a string at every space. I have successfully achieved this using .split(" "), but now I need to determine the length of each individual string. My goal is to check if a given string includes a midd ...

In JavaScript, sort the array of objects based on the key name

I have an array of objects like the following: employees = [ {name: "Tony Stark", department: "IT"}, {name: "Peter Parker", department: "Pizza Delivery"}, {name: "Bruce Wayne", department: "IT"}, {name: "Clark Kent", department: "Editin ...

Make sure to declare rest parameters first when using Typescript

I am dealing with a function that takes in multiple string arguments and one final argument of a complex type, which is called Expression. This particular code looks like this in JavaScript: function layerProp(...args) { const fields = args.slice(0, -1) ...

Issue with ng-repeat causing HTML table data to not appear

Trying to create a Flask web app, I encountered an issue while attempting to display tabular data on my webpage using AngularJS. Despite using ng-repeat to iterate through the data, it doesn't seem to work and no errors appear in the console. Can anyo ...

Utilizing properties from the same object based on certain conditions

Here's a perplexing query that's been on my mind lately. I have this object with all the styles I need to apply to an element in my React app. const LinkStyle = { textDecoration : 'none', color : 'rgba(58, 62, 65, 1)', ...

Can someone provide guidance on creating a Primeng Generic Group Array?

Here is my original object: users = [ {id: 1, name: "name1", company: "com1"}, {id: 2, name: "name2", company: "com2"}, {id: 3, name: "name3", company: "com1"}, {id: 4, name: "name4", company: "com2"}, {id: 5, name: "name5", company: "com3"}, ] ...

Having trouble retrieving data from the server for the POST request

I am fairly new to using Jquery and Ajax requests. I'm currently working on a website where I have a simple form that collects an email address from users and sends it to the server. However, I'm struggling to figure out how to capture the form d ...

Structural engineering for massive webpage

Currently I am in the process of building a large page using AngularJS. As I plan out the architecture for this page, I am debating which approach would be most effective. The page consists of 3 distinct blocks with various functionalities, but the prima ...

What is the best way to set values for the outcomes of a jQuery/AJAX post?

When sending data to a php page using jquery, I aim to receive the response from the page and store it in php variables on the original page without displaying results in the HTML or appending a DIV. Here's an example of how this can be achieved: Sam ...

Having difficulty extracting image and product names from Amazon or Flipkart pages using Jsoup

I'm having trouble retrieving the main image and product name from Amazon or Flipkart using Jsoup. This is my Java/Jsoup code: // For amazon Connection connection = Jsoup.connect(url).timeout(5000).maxBodySize(1024*1024*10); Document doc = connectio ...

Unable to implement the bootstrap panel class as expected

It seems like the bootstrap panel class is not being applied in this code snippet: <div class="container main-content"> <div class="row"> <div class="col-sm-3"> <div class="panel panel-primary"> ...

Looking for assistance with implementing touch gestures on an HTML website?

I am in the process of developing a web application, and I have implemented a menu bar that shifts when a user clicks on an arrow. Each click activates a new menu option. Currently, I am looking to provide users with the ability to swipe over the screen t ...

React - The ._id received by the Modal inside the map function is incorrect

My map is generating edit and delete buttons. The delete button requires confirmation, so I implemented a modal. When I use console.log(additive._id) on the first delete button, I get the correct ._id, but when I click the confirm button inside the modal, ...

Concealing the table border with the help of jQuery

I am working with a dynamically created tables in a ASP.NET repeater, where the number of tables can vary depending on the data retrieved from the database. Below is a sample markup along with the CSS and jQuery code. Please note that the tables are dynami ...

What causes getServersideprops to return undefined?

The data I am trying to fetch is showing as undefined in the console. Here is the code snippet: export default function Home({ data }) { console.log(data); return ( <div> <h2>Welcome !!</h2> </div> ); } export a ...

The animation for the CSS gradient background is failing to animate

After finding a similar code snippet used for backgrounds, I made some modifications to suit my needs. However, when attempting to implement it or any animation, nothing seems to be working. Even simple animations are not functioning as expected. While I a ...

implementing data in a single component using vue.js

I am facing an issue with a component where I need to fetch data using an ajax call. The component is being called correctly and the data is returned in the ajax call, but I am struggling to assign it to the data in the template? <template> < ...

The process of generating vue-cli-plugin-prerender-spa encountered an issue where the error was not found within the

I have successfully integrated this plugin into my laravel-vue application and configured it within the laravel mix's webpack.mix.js file. After running it via npm (using watch, dev, and prod modes), I encountered no errors. However, upon inspecting ...