x
 
<!DOCTYPE html>
<html>
<head>
<style>
.mystyle {
  width: 300px;
  height: 50px;
  text-align: center;
  background-color: coral;
  color: white;
  margin-bottom: 10px;
  float: left;
  margin: 8px;
}
</style>
</head>
<body>
<p>在本例中,我们搜索文档中的第一个 div 元素。然后,如果 div 元素的 id 为 "myDIV" - 更改其字体大小。</p>
<button onclick="myFunction()">试一试</button><br>
<div id="myDIV" class="mystyle">
I am a DIV element
</div>
<div class="mystyle">
I am also DIV element
</div>
<script>
function myFunction() {
  var x = document.getElementsByTagName("DIV")[0];
  
  if (x.id === "myDIV") { 
    x.style.fontSize = "30px";
  }
}
</script>
</body>
</html>