Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
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 answers
Answer question

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 Report

0

Try:

let trx = db.transaction(["nota"], "readwrite");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!