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

104
Views
Make function delete

I recently tried to make a page that saves the input and displays it on the page. Everything works but i want to add a delete button at every input, which deletes only one input. I tried so many different ways, but none of them worked. If you have any idea how to solve this, I would be grateful. Here is the code:


let savedinput = [] 

Localstoragesaves = localStorage.getItem("Zaznamki")
const Predpomnjenipodatki = JSON.parse(Localstoragesaves)

const DeleteButtonHTML = document.getElementById("izbrisi-gumb")
const userinput = document.getElementById("vnos-pr") 
const inputsavebutton = document.getElementById("vnos-gumb")
const LabelHTML = document.getElementById("seznamzaznamkov")
const SaveTab = document.getElementById("zavihek-gumb")
const DeleteLast = document.getElementById("pocisti-zadnjo")


if (Localstoragesaves) {
    savedinput = Predpomnjenipodatki
    Render(savedinput)
}

DeleteLast.addEventListener('click', function(){
    savedinput.pop()
    Render(savedinput)
})
SaveTab.addEventListener('click', 
function(){
    browser.tabs.query({active: true, currentWindow: true}, function(tabs){
        savedinput.push(tabs[0].url)
        localStorage.setItem("Zaznamki", JSON.stringify(savedinput))
        Render(savedinput)
        console.log( localStorage.getItem("Zaznamki") )
    })
})



function Render(parameter) {
    let tabslabel = ""
    for (i = 0; i < parameter.length; i++) {
    tabslabel += `   
    <li>
    <a href='${parameter[i]}' target='_blank'>${parameter[i]}</a> 
    </li>
    `
}

    LabelHTML.innerHTML = tabslabel  
}

DeleteButtonHTML.addEventListener('dblclick', 
    function() {
    localStorage.clear()
    savedinput = []
    LabelHTML.textContent = ''


})


inputsavebutton.addEventListener("click", function(){
    const Vsebinavnosa = userinput.value 
    savedinput.push(Vsebinavnosa)
    localStorage.setItem("Zaznamki", JSON.stringify(savedinput))
    Render(savedinput)
    userinput.value = ""
    console.log( localStorage.getItem("Zaznamki") )
    
})
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

I solved this problem myself. I'm quite proud ๐Ÿ˜. I want to thank you for your really quick responses even if I didnt get the solution here. If someone has the same problem I had, I will tell you what I did. In function render, I added a button with onclick function with argument, so that this new function which will be called will know which item from array needs to remove:

<button id="${parameter[i]}" onclick="Delete(${i})">Delete</button>

and then somewhere in this document I added this function which gets value from button click and knows which item from the array savedinput and localstorage needs to remove:

 function Delete(parameter) {
    mojizaznamki.splice(parameter, 1)
    console.log(savedinput)
    localStorage.setItem("Zaznamki", JSON.stringify(savedinput))
    Render(savedinput)
}

Hope this helps others. Greetings from Slovenia

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!