👩🏼‍💻바닐라 JS로 크롬 앱 만들기 : 2.16-3.2

change up·2023년 6월 5일
1

학습주제 : javascript에서 html로 접근하는 방법.

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel = "stylesheet" href="app.css">
    <title>Momentum</title>
</head>
<body>
    <div class =" hello ">
    <h1 id = "title">Grab me 1!</h1>
    </div>
    <div class =" hello ">
        <h1 id = "title">Grab me 2!</h1>
        </div>
        <div class =" hello ">
            <h1 id = "title">Grab me 3!</h1>
            </div>
    <script src = "app.js"></script>
</body>
</html>
//getElementById :document 함수중의 하나로 HTML에서 id를 통해 element를 찾는다.
//요소들을 가져와서 변경이 가능하게 만들어준다.

const title = document.getElementById("title");

title.innerText = "Got you!";

console.log(title.id);

//getElementByClassName ,getElementByTagName: array를 반환해준다
//querySelector 은 조건에 맞아도 단하나의 요소만 가져옴
//조건에 부합하는 모든걸 가져오려면 querySelectorAll을 사용한다.
const title = document.querySelector("hello .h1");
console.log(title);
profile
새싹이

0개의 댓글