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

106
Vistas
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 Respuestas
Responde la pregunta

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