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

154
Visualizações
Cannot read properties of null (reading 'querySelector')

im using firestore and trying to implement CRUD methods into my app,i successfully added and deleted and read documents however at the update,everytime i try to read some of the documents that i have added im getting the error Cannot read properties of null (reading 'querySelector') and i have no idea why it's occuring,the class exists,and it's being generated into html here is my code:

const recettecontainer = document.querySelector('.recettes');
recettecontainer.addEventListener('click', evt =>{

    //console.log(evt);
    if(evt.target.tagName === 'I'){
        const id= evt.target.getAttribute('data-id');       
        //db.collection('Recettes').doc(id).delete();
    }
    if(evt.target.textContent ==='edit'){
        const id =evt.target.getAttribute('data-id');
        const recette = document.querySelector(`.recette[data-id="${id}"]`);
        const titre = recette.querySelector('.titre').innerHTML;
        const type = recette.getElementById('.type').InnerHTML;
        console.log(titre,type);
    }

the error occures at const titre = recette.queryselector and here is the html that's being generated using javascript:

<div class = "recette" data-id="${id}">
        <tr class = "recette">
           <td class="titre">${data.titre}</td>
           <td class="type">${data.type}</td>
           <td>${data.operateur}</td>
           <td>${data.date}</td>
           <td>${data.control}</td>
           <td>${data.control1}</td>
           <td>${data.control2}</td>
           <td>${data.control3}</td>
           <td> ${data.control4}</td>
           <td> ${data.control5}</td>
           <td>${data.item1}</td>
           <td>${data.item2}</td>
           <td>${data.item3}</td>
           <td>${data.item4}</td>
           <td>${data.item5}</td>
           <td id="appadd">${data.additional}</td>
           <td><button data-id="${id}" data-target="side-form" ><i class="material-icons">edit</i></button></td>
           <td><div class="recipe-delete">
           <i class="material-icons" data-id="${id}">delete_outline</i>
         </div>
         </td>            
       </tr>
        </tbody>

id appreciate any help i can get note:the getElementbyId was just a test to see if it works by using an id instead of a class,but it also didnt work which is why i prefer if i can get help on queryselector

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Add an attribute for what the action is. Select the element with the attribute

<td>
  <button
    data-id="${id}"
    data-target="side-form"
    data-action="edit">
    <i class="material-icons">edit</i>
  </button>
</td>
<td>
  <div class="recipe-delete">
    <i 
      class="material-icons"
      data-id="${id}"
      data-action="delete"
    >delete_outline</i>
  </div>
</td>

and select it

const recetteContainer = document.querySelector('.recettes');
recetteContainer.addEventListener('click', evt =>{
  const elem = evt.target.closest('[data-action]');
  if (elem) {
    evt.preventDefault();
    const action = elem.dataset.action;
    const id = elem.dataset.id;
    switch (action) {
      case 'delete': 
        console.log('delete', id);
        break;
      case 'edit': 
        console.log('edit', id);
        break;
    }
  }
about 4 years ago · Juan Pablo Isaza Relatório
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