trying to make an auto delete rows script without deleting some specific lines with orden de venta #SO10100
let delete_nums = ["#SO202771", "#SO202772", "#SO202773"];
function getRowsToDelete() {
// Initialize an array that's going to contain all the rows to be deleted
let delete_rows = [];
// Get the element that contains all the rows
const ordenDeVenta = document.getElementsByClassName("uir-machine-row");
// Loop through all these rows
Array.from(ordenDeVenta).forEach(row => {
// Find the cell that contains the order no.
const cellWithNum = row.children[x];
// Go through each order no that has to be deleted
delete_nums.forEach(num => {
// If it's in the cell
if (cellWithNum.textContent.contains(num)) {
// Add the row to the array
delete_rows.push(row);
}
})
})
// Return the array with rows to be deleted
return delete_rows;
}
If you automatically want to make such as click on the element (as your title said), you can use:
row.click();
You should have an event on the row. Else, if it's on a button, search the button itself.
If you want to remove a line, you can use element.remove() that will do the job:
function del(id) {
document.getElementById("row-" + id).remove();
}
<table>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>
<tr id="row-1" onclick="del(1)">
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr id="row-2" onclick="del(2)">
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
</table>
Here, everything is simplified. In you case, instead of using getElementById you are using children element of getElementsByClassName.