setAttribute() 예제
<style> .hzcolor {color: red;} </style> <h1>홈짱닷컴 Homzzang.com</h1> <button onclick="hz()">클릭</button> <script> function hz() { document.getElementsByTagName("H1")[0].setAttribute("class", "hzcolor"); } </script> 결과보기
<style>
.hzcolor {color: red;}
</style>
<h1>홈짱닷컴 Homzzang.com</h1>
<button onclick="hz()">클릭</button>
<script>
function hz() {
document.getElementsByTagName("H1")[0].setAttribute("class", "hzcolor");
}
</script>
결과보기