body{
background-color: aqua;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>vanillaJS</title>
</head>
<body>
<div id="parent-id">
<h1 class="test">PCY 1</h1>
</div>
<script src="app.js"></script>
</body>
</html>
const oldBody = document.body;
oldBody.id = "first-id";
alert(oldBody.id);
newBody = document.createElement("body");
newBody.id = "second-id";
document.body = newBody;
alert(document.body.id);
index.html의 body 태그에 id를 setting하고, 추후에 변경하는 코드를 작성하였음
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>vanillaJS</title>
</head>
<body>
<div id="parent-id">
<h1 class="test">PCY 1</h1>
</div>
<script src="app.js"></script>
</body>
</html>
alert(document.head.id); // null
document.head.id = "first_head_id";
alert(document.head.id);
alert(document.head.baseURI);
alert(document.head.outerHTML);