There is a code:
<div id="div">текст</div> <script> div.insertAdjacentHTML('beforeBegin', '<p>Привет</p>'); div.insertAdjacentHTML('afterEnd', '<p>Пока</p>'); </script> I do not understand why the simple expression div.insertAdjacentHTML('afterEnd', '<p>Пока</p>'); works correctly.
Do not you first need to use getElementById () to find an element with id = div, assign this DOM object to a variable, and then insert something into it.
Why does this work?