본문 바로가기

javascript, framework/javascript

Step01_example1 (javascript에서 태그 접근하기)

html, head, meta, title, body, p 등의 태그는 object type 형식을 띄고 있다.

 

 

 

 

javascript로 특정 p태그에 접근해보기

 

앞서 배웠듯이

document.querySelectorAll("p")  에서 document는 뒤에 .이 있기에 object type,

document.querySelectorAll은 뒤에 ()이 오기에 function type인 것을 알 수 있다.

이후 NodeList(5) [p, p, p, p, p] 정보에 []를 보면 document.querySelectorAll("p")은 array type이다.

이후 출력되는 값이 p태그 이기 때문에 object type 뒤에 작성하는 .을 입력하고 innerText를 통해 해당 string type 문자를 출력한다.

 

 

 

접근을 완료한 뒤에는 변경을 해본다. 필자는 "김구라", 1, document.querySelectorAll("p")[1].innerText를 시도해봤다.