A
A
Adolf Milos2019-12-15 19:51:48
JavaScript
Adolf Milos, 2019-12-15 19:51:48

Why doesn't insertCell() work?

You need to write a class using OOP to work with a table. I wrote a constructor, but for some reason it does not work, it says that this.elem.insertCell() is not a function! Although insertRows() works fine.
Please tell me where I screwed up
JavaScript

let rows = 1, cells = 1;
class Table{
    constructor(){
        this.elem = document.createElement('table');
        this.elem.style.border='5px';

        document.body.appendChild(this.elem);

        this.elem.insertRow().innerHTML = "- - - - -"; // вставить строку 1 (работает)
        this.elem.insertRow().innerHTML = "| | | | |";  // вставить строку 2 (работает)
        
        this.elem.insertCell().innerHTML = "X X X X X"; // выдаёт ошибку

    }
    
}

let elem = new Table();

HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>PR5_1.8</title>
</head>
<body>
    <script src="index.js"></script>
</body>
</html>

Photo 1
5df66390d9569570372163.jpeg
Photo 2
5df66477eb96e336468333.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2019-12-15
@YAVAY

insertCell is a row(TableRow) method and you are trying to apply it to a table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question