i was trying to create a modal, please check my code

Harsha Satya Vardhan Vasamsett
  1. I was trying to create modal when ABCD is pressed and display A, B, C, D, and when EFGH is pressed another modal to display E, F, G, H.
  2. I was struggling with the errors in getElementByID and getElementsByClass

I am sure I am doing wrong in js logic can anyone point out, please.

var btn = document.getElementsByClassName('firstpage').addEventListener('click',function(){
  var modal = document.getElementsById("mode");
  modal.style.display = 'block';
} );
.modal1{
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgb(0,0,0);
  background-color: rgba(0,0,0,0.4);
}

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

.key{
  display: grid;
  grid-template-columns: auto auto auto;
  background-color: #fefefe;
  padding : 20px;
  border: 1px solid #888;
  width: 80%;
}
<html>
  <div class='firstpage'>
    <div class='key'>ABCD</div>
    <div class='key'>DEFG</div>
  </div>
  
  <div id='mode' class='modal1'>
    <div class='key'>A</div>
    <div class='key'>B</div>
    <div class='key'>D</div>
    <div class='key'>E</div>
  </div>
  
  <div class='modal2'>
    <div class='key'>F</div>
    <div class='key'>G</div>
    <div class='key'>H</div>
    <div class='key'>I</div>
  </div>
</html>

iota

You should use document.querySelectorAll and loop over all the elements to add event listeners to them.

document.querySelectorAll('.firstpage > .key').forEach((el,idx)=>el.addEventListener('click', function(e){
  document.querySelector(`.modal${idx + 1}`).classList.add('active');
}));
.modal1 {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgb(0, 0, 0);
  background-color: rgba(0, 0, 0, 0.4);
}

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

.key {
  display: grid;
  grid-template-columns: auto auto auto;
  background-color: #fefefe;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
}

.active {
  display: block;
}
<div class='firstpage'>
  <div class='key'>ABCD</div>
  <div class='key'>DEFG</div>
</div>

<div id='mode' class='modal1'>
  <div class='key'>A</div>
  <div class='key'>B</div>
  <div class='key'>D</div>
  <div class='key'>E</div>
</div>

<div class='modal2'>
  <div class='key'>F</div>
  <div class='key'>G</div>
  <div class='key'>H</div>
  <div class='key'>I</div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

i am trying to create foreign keys but i got error 1822 .. please see my code below

I am trying to create circle avatar in Flutter. I have tried this but not giving me circle please check the code bellow:

I am trying to write a code but facing a java.lang.StringIndexOutOfBoundsException. Please check the code out

I am unable to Decrypt my text but I am able to encrypt can someone please check my code

i am trying to create a simple api to recieve any format of json data but getting 400 bad request.. please have a look to my code and correct

Please check the error in my code for increment of an integer

What is wrong with my code, Please check my code?

identify the visitors country:-my code is working perfectly in my local machine. But when i host its not working please check

Python, code works in the command line, but not when trying to create a program, please

Iam trying to update the state "Experience" but I didn't get updated value. please correct if my code is wrong

android AccessibilityService suddenly stopped triggerring events - check my code please

How to access the Web using VBA? Please check my code

Can't get javascript working (beginner) - please check my code

Could someone please check my Tkinter and python code with a textfile?

Please check my code i wanted to make use of while where the condition must stop when user enter 0 in first input

I'm trying to get my code to create a student database and no matter what I try it errors

I am trying to check that If email already exist in databse or not or not in database but my code throws error

Shrink my code, Please

I am trying to create one randomly selected individual to be positive in a random distribution, but my code is incorrect

I am trying to create drop down menu in django but my code is showing only text box ? Help Appricated

Is my code crashing because of internet connection issue? if so is there a way i can make a snippet of code to check connection before trying api?

Please, how do I embed the blue container in my code

I am trying to create a code to simulate a lottery game. I need to check if one of the generated numbers already has been generated before

I'm getting error "detail": "JSON parse error - Expecting ',' delimiter: line 4 column 19 (char 64)" while trying to run my code, anyone please?

Trying to create a guess my letter code. How do I incorporate the case where the input char from the user equals my letter?

I am Trying to create my first Django Project on VS Code and I cant figure out how properly install the packages needed

Trying to understand recursion in JS... check my simple code

C++, Can I use default constructor in builder pattern? Please check my problem and my solution

Please rectify my entropy code