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

179
Visualizações
addEventListener function doesn't work properly in js

I want to add an event listener to a list of objects but when i use the following code it works like this. the function only happens only one time when i run the app ( without clicking on the element) and then it stops working. js :

             const checkIcons = document.getElementsByClassName("checkIcon");
             var checkIconFunction = function(img){
                
                console.log(img.src)
                var filename = img.src.replace(/^.*[\\\/]/, '');
                console.log(filename)
                if (filename == "cheack-icon.svg" ){
                    img.src = "../svg/color/cheack-icon-filled.svg";
                }else{
                    img.src = "../svg/color/cheack-icon.svg";
                };
                
            };
            Array.from(checkIcons).forEach(function(element) {
                element.addEventListener('click', checkIconFunction(element));
            });

html:

         <section class="section" id="activity-table">
            <h2 id="activity-label">Activity:</h2>
            
            <table class="table">
                <tr>
                    <th>
                        time
                    </th>
                    <th>
                        directory
                    </th>
                    <th id="selected-boolean">
                        select
                    </th>
                    
                </tr>
                
                <tr class="row">
                    <td>
                        <span>19 May</span>
                    </td>
                    <td>
                        <span>ali/ali/ali</span>
                    </td>
                    <td>
                        <img  id="check-icon" class="icon checkIcon" src="../svg/color/cheack-icon.svg" width="20" height="20">
                    </td>
                </tr>
                <tr class="row">
                    <td>
                        <span>19 May</span>
                    </td>
                    <td>
                        <span>ali/ali/ali</span>
                    </td>
                    <td>
                        <img  id="check-icon" class="icon checkIcon" src="../svg/color/cheack-icon.svg" width="20" height="20">
                    </td>
                </tr>
            </table>
        </section>

i

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