From fabe517083cb50d81212c497777ac1d1f55dcb09 Mon Sep 17 00:00:00 2001 From: Huda Date: Fri, 20 Jun 2025 14:28:02 -0400 Subject: [PATCH 1/5] Implemented add row button functionality --- main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.js b/main.js index 79a0fd1..0e8b665 100644 --- a/main.js +++ b/main.js @@ -5,3 +5,17 @@ root.addEventListener("click", (event) => { console.log(event.target.tagName); console.log(event.target); }); + +const table = document.getElementsByTagName("table")[0]; +const rows = table.rows.length; +const columns = table.rows[0].cells.length; + +// Add rows to grid +const addButton = document.getElementById("add-row"); +addButton.addEventListener("click", () => { + table.insertRow(rows - 1); + for(let i = 0; i < columns; i++) { + table.rows[rows - 1].insertCell(0); + } +}) + From 69be132b32b723b6c707b18c9b801c4fd2a5620e Mon Sep 17 00:00:00 2001 From: Huda Date: Fri, 20 Jun 2025 14:36:37 -0400 Subject: [PATCH 2/5] Implemented add column button functionality --- main.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 0e8b665..81cc839 100644 --- a/main.js +++ b/main.js @@ -7,8 +7,8 @@ root.addEventListener("click", (event) => { }); const table = document.getElementsByTagName("table")[0]; -const rows = table.rows.length; -const columns = table.rows[0].cells.length; +let rows = table.rows.length; +let columns = table.rows[0].cells.length; // Add rows to grid const addButton = document.getElementById("add-row"); @@ -17,5 +17,14 @@ addButton.addEventListener("click", () => { for(let i = 0; i < columns; i++) { table.rows[rows - 1].insertCell(0); } + rows++; }) +// Add columns to grid +const addColumnButton = document.getElementById("add-column"); +addColumnButton.addEventListener("click", () => { + for(let i = 0; i < rows; i++) { + table.rows[i].insertCell(0); + } + columns++; +}) From 9a820016913c91d2063aae62b89526d837ca70c8 Mon Sep 17 00:00:00 2001 From: Huda Date: Fri, 20 Jun 2025 14:37:08 -0400 Subject: [PATCH 3/5] Renamed addButton to addRowButton --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 81cc839..e80c220 100644 --- a/main.js +++ b/main.js @@ -11,8 +11,8 @@ let rows = table.rows.length; let columns = table.rows[0].cells.length; // Add rows to grid -const addButton = document.getElementById("add-row"); -addButton.addEventListener("click", () => { +const addRowButton = document.getElementById("add-row"); +addRowButton.addEventListener("click", () => { table.insertRow(rows - 1); for(let i = 0; i < columns; i++) { table.rows[rows - 1].insertCell(0); From a67cc0fd590bacce88d1fe6c57cea8df337035c5 Mon Sep 17 00:00:00 2001 From: Huda Date: Fri, 20 Jun 2025 14:52:34 -0400 Subject: [PATCH 4/5] Implemented remove rows button --- index.html | 2 ++ main.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/index.html b/index.html index 1a138b6..bce872b 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,9 @@

Grid Maker

+ +