Last active
February 27, 2022 07:03
-
-
Save cthae/f84a50bcd765f74596ae3017c513d44e to your computer and use it in GitHub Desktop.
adding a row into a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addSource(){ | |
const count = document.querySelector("table#mainSources").querySelectorAll("tr").length; | |
const newRow = document.querySelector("tr#tr-0").cloneNode(true); | |
newRow.id = "tr-"+count; | |
newRow.querySelectorAll("td").forEach(td => { | |
const name = td.getAttribute("name"); | |
if (name == "alias" || name == "mID"){ | |
td.querySelector("label").innerHTML = td.querySelector("label").innerHTML.replace(":", " " + count + ":"); | |
td.querySelector("input").id = td.querySelector("input").getAttribute("id").replace("0",count); | |
td.querySelector("input").value = ""; | |
} | |
}) | |
document.querySelector("table#mainSources").appendChild(newRow); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment