JavaScript

Tag의 id값을 이용하여 접근하여 css바꾸기

CleanSense 2018. 3. 12. 20:13
728x90

document.getElementById("id명")으로 접근후 .style 으로 css를 변경한다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
<body>
 
<h2>id="demo"인 p태그의 css 바꾸기</h2>
 
<p id="demo">버튼을 클릭하면 이곳의 css가 바뀝니다.</p>
 
<button type="button" onclick="document.getElementById('demo').style.color='Tomato'">
Click Me!
</button>
 
</body>
</html
cs

id="demo"인 p태그의 css 바꾸기

버튼을 클릭하면 이곳의 css가 바뀝니다.



728x90