When I create a new element, such as div
, it automatically generates both an opening and closing tag. However, when creating an element like canvas
, only the opening tag is generated. Why does this happen?
document.createElement('div');
This code results in <div></div>
.
document.createElement('canvas');
Executing this code will create <canvas>
. If a child element is appended to it, then it will become
<canvas>childTag</canvas>
. Are there specific reasons for this behavior? Which other elements behave similarly to canvas
? And which elements act like the aforementioned div
? Is the closing tag for canvas
optional?