Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda