버튼 누를시 버튼 배경색 변경을 자바스크립트를 이용해서 해보기

<!DOCTYPE html>
<html>
  <head>
  	<style>
    #btn1{
    	border: 2px solid blue;
        color: red;
        background-color:rgba(0,0,0,0);
        margin: 20px;
        padding : 10px;
        border-radius: 20px;
    }
  	</style>
  </head>
  <body>
  	<button id="btn1">버튼테스트</button>
    <script>
    btn1.addEventListener('click', () => {
      if(btn1.style.backgroundColor == 'blue'){
      btn1.style.backgroundColor = 'white';
      }
      else{
      btn1.style.backgroundColor = 'blue';
      }
    });
    </script>
  </body>
</html>

'javaScript' 카테고리의 다른 글

자바 스크립트의 변수  (1) 2023.07.18

+ Recent posts