[코딩애플] 실용 자바스크립트 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>

 

 

 

유튜브 답)

위와 같음