[코딩애플] 실용 자바스크립트 1강 : 셀렉터 selector
2023. 1. 22. 01:31ㆍ언어(Language)/Javascript
[getElementById]
https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
Document.getElementById() - Web APIs | MDN
The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quick
developer.mozilla.org
[innerHTML]
Element.innerHTML - Web APIs | MDN (mozilla.org)
Element.innerHTML - Web APIs | MDN
The Element property innerHTML gets or sets the HTML or XML markup contained within the element.
developer.mozilla.org
실습 내가 작성한 답)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body {
font-size: 30px;
}
</style>
</head>
<body>
<h2 id="hello">안녕하세요</h2>
<h2 id="hi">올때메로나</h2>
<script>
document.getElementById('hello').innerHTML='안녕';
document.getElementById('hi').innerHTML='올때바밤바';
</script>
</body>
</html>
힌트 보고 작성한 답)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h2 id="hello">안녕하세요</h2>
<h2 id="hi">올때메로나</h2>
<script>
document.getElementById('hello').innerHTML='안녕';
document.getElementById('hi').innerHTML='올때바밤바';
document.getElementById('hello').style.fontSize="30px";
document.getElementById('hi').style.fontSize="30px";
</script>
</body>
</html>
유튜브 답)
위와 같음
'언어(Language) > Javascript' 카테고리의 다른 글
JavaScript의 함수 (0) | 2023.02.02 |
---|---|
[코딩애플] 실용 자바스크립트 3강 : function 언제 쓰는지 아셈? + 간단한 버그 찾는 법 (0) | 2023.01.22 |
[코딩애플] 실용 자바스크립트 2강 : Alert 만들어서 유저 위협하기 (0) | 2023.01.22 |
[Do it! 자바스크립트 입문] 05장 함수와 이벤트 (0) | 2023.01.02 |
[Do it! 자바스크립트 입문] 04장 제어문 (0) | 2023.01.01 |