Result Size: 625 x 534
x
 
<!DOCTYPE html>
<html>
<head>
<style>
.anchors {
  display: block;
  padding: 5px;
  background-color: black;
  color: white;
}
#myAnchor {
  background-color: dodgerblue;
}
</style>
</head>
<body>
<a class="anchors" id="myAnchor" href="https://www.begtut.com/html/">HTML</a>
<a class="anchors" href="https://www.begtut.com/css/">CSS</a>
<a class="anchors" href="https://www.begtut.com/js/">JavaScript</a>
<p>点击按钮显示上面第一个链接的id属性值。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  var x = document.getElementsByClassName("anchors")[0].id;
  document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>