Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save theskillwithin/4a116e3d48f9717d10271521cb015b89 to your computer and use it in GitHub Desktop.
Save theskillwithin/4a116e3d48f9717d10271521cb015b89 to your computer and use it in GitHub Desktop.
adding a row into a table
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