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

195
Vistas
Using indexedDB, I have a event listener which calls a function when a div is clicked, but it doesn't work

I have this function:

function event_erase_nota (){
       
    document.addEventListener('click', (e)=> {
    let elementParent = e.target.parentNode;
        
        if (elementParent.className == 'delete'){
            id = elementParent.parentNode.id;
            
            console.log(id) 
            erase_nota(id)
       }
    })
}
event_erase_nota()

Detect when a div with the class 'delete' is clicked and call the function erase_nota that is on other archive.


function erase_nota (id) {
    const request = indexedDB.open("noto", 1);
    
    request.onsuccess = (event) => {
        var db = event.target.result;
        
        let trx = db.transaction("nota", "readwrite");
        let request = trx.objectStore("nota").delete(id);
        
        trx.oncomplete = function () {
            console.log("Nota eliminada")
            
            db.close();
        }
    }
} 

But the note stores in the data base doesn't get erased! When I call the function 'erase_nota(someId)' in the console works fine.

What's wrong?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The problem was the type of the variable id:

if (elementParent.className == 'delete'){
            id = elementParent.parentNode.id;
            
            console.log(id) 
            erase_nota(id) // 

I checked the typeof id and was a string, so I convert it to Number,

if (elementParent.className == 'delete'){
            id = elementParent.parentNode.id;
            
            console.log(id) 
            erase_nota(Number(id)) 

Now it works!

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try:

let trx = db.transaction(["nota"], "readwrite");
about 4 years ago · Juan Pablo Isaza Denunciar
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