<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="parent-id">
<p>hello word1</p>
<p id="test1">hello word2</p>
<p>hello word3</p>
<p>hello word4</p>
</div>
<script>
let element = document.createElement('div');
element.id = 'test';
document.body.appendChild(element);
document.getElementById('test').textContent = 'hahasibar';
const $ul = document.querySelector('section > ul')
['상추','가지','브로콜리'].forEach(itm=>{
$el = document.createElement('li');
$el.textContent = itm;
$ul.appendChild($el);
});
</script>
</body>
</html>
댓글 영역