본문 바로가기
부트캠프교육중/JavaScript

[JS] 노마드코더

by 뭉지야 2023. 8. 16.
728x90

getElementById
- string을 전달받는 함수
- html에서 id를 통해 element를 찾아준다.
- getElementById란 함수를 통해 id로 element를 가져올수 있다.

document.getElementById("title")

title이라고 써있는 자리에는 id를 써야 하는데 string이어야 한다!!!




querySelector
- element를 css방식으로 검색할수 있다.
- querySelector에는 hello가 classname이라는 것과 그 안의 h1을 명시해줘야한다.
- getElementByName이면 hello만 써도된다.

document.querySelector(".hello h1");
getElementsByClassName("hello")

querySelectorAll
- selector안의 조건에 부합하는 모든 element를 가져다준다.



title.addEventListener()
-자바스크립트에 무슨 event를 적용할건지 알려줘야한다.

title.addEventListener("click")

function handleTitleClick() {
  console.log("title was clicked!");
}
title.addEventListener("click", handleTitleClick);
title을 click할 경우에 handleTitleClick함수를 실행한다.

728x90

'부트캠프교육중 > JavaScript' 카테고리의 다른 글

[JS] while  (0) 2023.10.31
[JS] 자주이용하지만 자주 헷갈리는 splice부분  (0) 2023.09.07
[JS] express  (0) 2023.08.11
[JS] Math  (0) 2023.08.10
[JS] new Date  (0) 2023.08.10