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

202
Views
Delete table row with JavaScript?

I am adding some data with JavaScript with no problem but I wanted to delete a row by adding delete button inside the row which I add, but I couldn't do it. The code is below. The delete button doesn't work:

const ad = document.querySelector("#ad");
const soyad = document.querySelector("#soyad");
const yas = document.querySelector("#yas");
const ekle = document.querySelector("#ekle");
const liste = document.querySelector("#liste");

ekle.onclick = function() {
  let tAd = document.createElement("td");
  let tSoyad = document.createElement("td");
  let tYas = document.createElement("td");
  let tSil = document.createElement("td");
  let silBtn = document.createElement("button");
  silBtn.textContent = "Sil";
  tAd.textContent = ad.value;
  tSoyad.textContent = soyad.value;
  tYas.textContent = yas.value;
  let tr = document.createElement("tr");
  tr.appendChild(tAd);
  tr.appendChild(tSoyad);
  tr.appendChild(tYas);
  tr.appendChild(silBtn);

  liste.appendChild(tr);
  ad.value = "";
  soyad.value = "";
  yas.value = "";
  ad.focus();

}
silBtn.onclick = function(e) {
  tr.appendChild(tAd);
  tr.appendChild(tSoyad);
  tr.appendChild(tYas);
  tr.appendChild(silBtn);
  liste.removeChild(this.parentNode.parentNode);
}
<div id="sayfa">
  <label for="">Ad:</label>
  <input type="text" id="ad">
  <label for="">Soyad</label>
  <input type="text" id="soyad">
  <label for="">Yas</label>
  <input type="text" id="yas">
  <button id="ekle">Tabloya Ekle</button>
  <table id="liste">
    <tr>
      <th>Ad</th>
      <th>SoyAd</th>
      <th>Yaş</th>
      <th>Sil</th>
    </tr>
  </table>
</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use This Javascript

<script>
const ad=document.querySelector("#ad");
const soyad=document.querySelector("#soyad");
const yas=document.querySelector("#yas");
const ekle=document.querySelector("#ekle");
const liste=document.querySelector("#liste");

ekle.onclick=function(){  
let tAd=document.createElement("td");
let tSoyad=document.createElement("td");
let tYas=document.createElement("td");
let tSil = document.createElement("td"); 
let silBtn =document.createElement("button");
silBtn.textContent="Sil";
tAd.textContent=ad.value;
tSoyad.textContent=soyad.value;
tYas.textContent=yas.value;
let tr=document.createElement("tr");
tr.appendChild(tAd);
tr.appendChild(tSoyad);
tr.appendChild(tYas);
tr.appendChild(silBtn);

liste.appendChild(tr);
ad.value="";
soyad.value="";
yas.value="";
ad.focus();
silBtn.onclick=function(e){ 
  liste.removeChild(this.parentNode); 
      }  
}
</script>
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!