Create a simple dynamic grid using JavaScript, HTML

preview_player
Показать описание
As an example, we used a Udacity project "Pixel Art Maker" starter files.
Рекомендации по теме
Комментарии
Автор

keep going girl, need some css html recap, will watch your videos

pawel_html
Автор

Priviet Natalia, :) I wanted to thank you for your gridMaker code! :D

Here are my results:

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Grid</title>
<style>
/* Add CSS styles for the grid cells if needed */
table {
border-collapse: collapse;
}

td {
width: 30px;
height: 30px;
border: 1px solid black;
}
</style>
</head>
<body>

<!-- Form to submit grid size -->
<form id="sizePicker">
Grid Height:
<input type="number" id="inputHeight" name="height" min="1" max="20">
Grid Width:
<input type="number" id="inputWidth" name="width" min="1" max="20">
<input type="submit">
</form>

<!-- Grid container -->
<table id="pixelCanvas">
<!-- Grid cells will be dynamically added here -->
</table>

<script>
// Function to create grid
function makeGrid() {
// Get the user input for grid size
const height =
const width =

// Get the grid container
const gridContainer =

// Clear existing grid
gridContainer.innerHTML = '';

// Create new grid
for (let i = 0; i < height; i++) {
const row = document.createElement("tr");
for (let j = 0; j < width; j++) {
const cell = document.createElement("td");
row.appendChild(cell);
}

}
}

// Event listener for form submission
document.getElementById("sizePicker").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent default form submission behavior
makeGrid(); // Call makeGrid function when form is submitted
});
</script>

</body>
</html>

skyrockstartrade
Автор

how is this dinamic if the 11 is hardcoded ?

islacassamo
Автор

Small doubt how can I add click event on each record

lokeshbsr
Автор

i tried your code but it didn't work! idk why

suzansamer
Автор

i tried your code but it didn't work.. i'm still trying to fix it but thank you anyways :)

lesnoopy
welcome to shbcf.ru