티스토리 뷰

.html페이지에 모든것을 담지않고, .css .js 파일로 각각 처리를 한 후에

<link rel="stylesheet" href="index.css"/>   <script src="index.js"></script> 이런식으로 넣어주면 한페이지에 다 때려박지 않아 정돈이 잘 된 코드들을 볼 수 있다.

 

id를 선언할때는 #, class를 선언할때는 . 으로 시작된다.

 

document.getElementById(" ") 는 id에 의해 구분되는 element를 가져와서 그것의 값을 가져와라 라는 함수이다.

<h1 id="title">hello>/h2>

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

console.log(title)
console.error(whatthe)
title.innerHTML = "Hi! from JS"

h1에 hello라고 적어놔서 출력이 hello라고 되야하지만, innerHTML을 사용해서 Hi! from JS로 변환시킬 수 있다. 이것이 자바스크립트의 힘이다. 또한 html에서 자바스크립트로 선택한 모든 것은 object객체가 될수 있다. 

 

 

'노마드코더 > 자바스크립트' 카테고리의 다른 글

#2-4 Events and event handlers  (0) 2021.08.29
#2-3 Modifying the DOM with JS  (0) 2021.08.29
#2.1.1 More Function Fun  (0) 2021.08.29
#1-10 Organizing Data with Objects  (0) 2021.08.27
#1-9 Organizing Data with Arrays  (0) 2021.08.27
댓글
© 2018 webstoryboy