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

119
Views
Is there a way to allow the popup image to close when clicked anywhere on the screen, using JavaScript and jQuery?

Currently, when i click on an image, it is able to popup and close. However it only closes when i click on the popup image.

Here is my code:

$(document).ready(eventlistener); 
function eventlistener() {
$(".img-thumbnail").click(popupImage); }   
function popupImage() {
var srcname = $(this).attr("src"); 
var newImage = srcname.replace("small", "large"); 

if ($(this).parent().children("span").children("img").hasClass("image-popup")) 
{ 
    
    $(this).parent().children("span").remove(); 
    
} else {
    var printing = "<span><img class=\"image-popup\"src=\"" + newImage + "\"></img></span>";
    $(this).after(printing); 
}}

I searched through stackoverflow and know that many have asked this question and google and tried but wasnt able to fix the issue.

Is there a way that i can modify it to allow the popup image to close whenever i click anywhere on the screen?

Please help. Thanks.

about 4 years ago · Juan Pablo Isaza
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!