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

105
Visualizações
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 Respostas
Responde à pergunta

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 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