Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Project that makes a grid and on click adds color to a cell.
- So the forum mentor told me to start it this way with the handler...
- 1.
- function makeGrid() {
- for (let i = 0; i < pHeight.value; i++) {
- const row = pCanvas.insertRow(i);
- for (let j = 0; j < pWidth.value; j++) {
- const cell = row.insertCell(j);
- cell.addEventListener('click', function() {
- this.style.backgroundColor = colorPicker.value;
- })
- }
- }
- }
- So I made the cellClickAddColor on mousedown whether LMB or RMB that adds or clears a cell.
- Then I added cellHoverAddColor, same principle.
- Then cellClear, again, same way to do it.
- Then I wanted to make a input submit (id btn1) to be disabled (unclickable) when there is not a single colored cell, and enabled when there is at least 1 colored one. Wanted to put it inside the hover to check it when it enters a cell for all cells and then do it's job.
- Then I could just put manually btn1.disable=false/true to each button, but that's bad or good practice? I guess bad.
- So I wanted to make a function cellColorCheck that would check the cells for colored ones and if there is to place btn1.disabled=false;
- Now I tried several ways but it doesn't work with using the cell from the makeGrid() iteration.
- How do I do it?
- Was going this way overall bad?
- Is this even possible or do I have to go around it and make it differently?
- I am a newbie so I ask people to tell me because I don't know :)
- Thanks for your time!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement