Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
How can I close layer popup when I click background or button?

The scenario is as follows.

enter image description here

  1. Default Status (no layer popup)
  2. When I click the button, layer popup shows.
  3. Click the button or outside, layer popup will be hide.

I want to close the layer popup when I click background(outside) or button.

How can I do with Vanilla JS or jquery? (based on HTML)

I would appreciate it if you could answer.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

When you open the popup attach a click listener to body that closes it and removes the listener.

about 4 years ago · Juan Pablo Isaza Report

0

You can use this code

//use by id

document.getElementById(#id).style.display = 'block';
document.getElementById(#id).style.display = 'none';

//use by className 



document.getElementById(.className).style.display = 'none';
document.getElementById(.className).style.display = 'block';

or use jQuery

$(document).ready(function(){
       $("#id").click(function(event){
         // $("#id").toggle();
         // $("#id").hide();
         // $("#id").show();
       });
     });
about 4 years ago · Juan Pablo Isaza Report

0

Set id for your layer in HTML part like id="layerPopup" Then on your JS code create event for your button

$(document).on('click', '#btnId', function(){ 
    $("#layerPopup").hide();

});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!