TIL 44일_2차

Moon-Tree·2023년 3월 6일
0
<head>
	<script type="text/javascript">
        function changeRed() {
            //document.querySelector는 (h1)지정한 대상을 찾아서 값을 target에 반환하는 메서드
            var target = document.querySelector("h1"); 
            // target.style = "color:red"; //기존 스타일이 사라지는 문제가 발생
            target.style.color = "red"; //해결방안 : 스타일 중 원하는 속성만 변경된다.
        }
	</script>
</head>

<body>
    <h1 style="text-decoration: underline;">Hello Javascript!</h1>
    <button onclick="changeRed();">빨강</button>
</body>

◆ 코드 작성시 주의사항

  • 태그명보다는 class명 또는 id를 적어주는 것을 권장한다.
profile
Backend Developer

0개의 댓글