JSFiddle - React, Tailwind, and code Playground
by trolleymusic
HTML
<table id="produse">
<tr id="tr1"><td><a href="#" id="butons1">click</a></td></tr>
<tr id="tr2"><td><a href="#" id="butons2">click</a></td></tr>
<tr id="tr3"><td><a href="#" id="butons3">click</a></td></tr>
<tr id="tr4"><td><a href="#" id="butons4">click</a></td></tr>
<tr id="tr5"><td><a href="#" id="butons5">click</a></td></tr>
<tr id="tr6"><td><a href="#" id="butons6">click</a></td></tr>
<tr id="tr7"><td><a href="#" id="butons7">click</a></td></tr>
</table>
JavaScript
var k;
var i = 1;
function stergeLinie(k) {
console.log("k: " + k);
var tabel = document.getElementById('produse');
// Add 1 to the rowCount because the elements have been assigned
// ids starting with 1, and length is 0-based
var rowCount = tabel.rows.length + 1;
var row = document.getElementById("tr" + k);
row.parentNode.removeChild(row);
var t = rowCount;
console.log(t, k);
for (var y = k; y < t; y++) {
console.log("Loop: " + y);
// If the elements don't exist anymore because they were removed
// skip the loop
if (!document.getElementById("butons" + (y + 1))) {
continue;
}
document.getElementById("butons" + (y + 1)).onclick = function onclick(event) {
// Get the number out of the
// id of the element that was clicked
var x = parseInt(this.id.replace("butons",""));
console.log("x: " + x);
stergeLinie(x);
}
}
}
stergeLinie(1);