<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My JavaScript</title>
</head>
<body>
<ul>
<li>Taro</li>
<li>Jiro</li>
<li>Saburo</li>
</ul>
<button>OK</button>
<script src="main.js"></script>
</body>
</html>
main.js
'use strict';
{
document.querySelector('button').addEventListener('click', () => {
// document.querySelector('li').textContent = 'Changed!';
// document.querySelectorAll('li')[0].textContent = 'Changed!';
// document.querySelectorAll('li')[1].textContent = 'Changed!';
// document.querySelectorAll('li')[2].textContent = 'Changed!';
document.querySelectorAll('li').forEach((li) => {
li.textContent = 'Changed!';
});
});
}