From d03aa9cfe96ae3a9eaa9acaf1312720243100cac Mon Sep 17 00:00:00 2001 From: Mekhribon Yusufbekova Date: Tue, 22 Jul 2025 00:40:34 -0400 Subject: [PATCH] Implement add row functionality -closes #1 --- main.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main.js b/main.js index 79a0fd1..bc0a8a1 100644 --- a/main.js +++ b/main.js @@ -5,3 +5,31 @@ root.addEventListener("click", (event) => { console.log(event.target.tagName); console.log(event.target); }); + + + +document.getElementById('add-row').addEventListener('click', function() { + + console.log("Add row button was clicked!"); + + const tbody = document.querySelector('tbody'); + console.log("Found tbody:", tbody); + + const firstRow = tbody.querySelector('tr'); + const columnCount = firstRow.children.length; + console.log("Number of columns:", columnCount); + + const newRow = document.createElement('tr'); + console.log("Created new row:", newRow); + + for (let i=0; i < columnCount; i++) { + const newCell = document.createElement('td'); + newRow.appendChild(newCell); + + } + console.log("Added", columnCount, "cells to new row"); + + tbody.appendChild(newRow); + console.log("Row added to table!"); + + }); \ No newline at end of file