2

I've generated a table in my html by using this code:

 var board=document.getElementById("tab");

    for(var i=0; i<lvl1.rows; i++ )
    {

            var row=board.insertRow();

            for(var j=0; j<lvl1.cols; j++)
            {
                var cell = row.insertCell();       
            }       
    }

The point is to keep the design of the page almost totally separated from the game engine (creating a Minesweeper game). Imagine I want to change the colour of the cell in position [2][3]. How can I change the background colour of this cell if I don't have the "td's" and "tr's" in the HTML code?

Thanks

2 Answers 2

2

To access the ith cell of row j, use:

board.rows[j].cells[i]
Sign up to request clarification or add additional context in comments.

Comments

0

You can set the background color style of a cell like this.

board.rows[j].cells[i].style.backgroundColor = "red";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.