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

155
Visualizações
I used javascript/jquery to allow images on my website to popup, but it does not seem to work

When i click on an image, the popup does not seem to work, and there are no error messages as well. I searched google for examples but it doesnt work.

Here is my javascript code:

function eventHandlers(){
$(".img-thumbnail").click(togglePopup);}
function togglePopup(e){
var popup = document.getElementById("id_popup");

if (popup === null)
{
    
    popup = document.createElement("span");
    popup.id = id_popup;
    popup.setAttribute("class","image-popup");
    
    var thumbnail = e.target;
    var small_image = thumbnail.src;
    var large_image = small_image.replace("_small","_large");
    popup.innerHTML = '<img src=' + large_image + '>';
    
    thumbnail.insertAdjacentElement("afterend",popup);
} else
{
    $('#' + id_popup).remove();
}}

Code in the main file:

<figure>                 
     <img src="images/test.jpg" class="img-thumbnail" alt="Test" title="View larger image..."/>
     <span id="id_popup"
                    <span id="id_popup" class="image-popup"></span>
                    <figcaption>Standard Test</figcaption>
 </figure>

And my css code:

.image-popup {
border: 5px solid lightgrey;
margin-left: 25%;
margin-top: -60%;
height: 40vh;}

Additionally is there a way that i can modify my javascript file to allow the popup to close when clicked anywhere on the screen?

Help will be really appreciated. 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