Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda