Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- javascript코딩테스트
- 협업프로젝트
- 콜백함수
- couchcoding
- db.json
- React state
- JavaScript
- Redux
- foreach
- first-child
- redux toolkit
- 카우치코딩
- 자바스크립트
- line-through
- 6주포트폴리오
- javascript React
- redux 사용방법
- react
- 블럭요소
- 인라인블럭
- useEffect
- useSearchParams
- react redux
- 자바스크립트배포
- React onClick
- useParams
- sort
- Redux store
- JSON
- toString
Archives
- Today
- Total
개발하는 루루언니
노드조작하기 : textContent , innertext , innerHTML 본문
728x90
반응형
document.querySelector( " #태그명 " ) ex ) p
document.getElementById(" 아이디값 " ) ex ) title
<h1 id="title">h1 <span style="display: none;">javascript</span></h1>
<script>
const pEl = document.getElementById("title")
console.log(pEl.textContent)
</script>
textContent :
textContent는 태그는 가져오지 않고 text만 가져온다. 근데 css로 span태그안에 javascript를 가렸는데도
콘솔창에는 출력이 되는걸 알 수 있다.
<h1 id="title">h1 <span style="display: none;">javascript</span></h1>
<script>
const pEl = document.getElementById("title")
pEl.textContent ='안녕하세요'
이렇게 직접 변수명.textContent = ' 글자 ' 입력을 해서 직접 글자를 출력할 수도있다.
innerText :
<h1 id="title">h1 <span style="display: none;">javascript</span></h1>
<script>
const pEl = document.getElementById("title")
console.log(pEl.textContent)
console.log(pEl.innerText)
</script>
innerText를 하면 내가 css 숨긴 자바스크립트는 출력해도 보이지 않게 된다.
pEl.innerHTML ='안녕하세요'
이렇게 변수명에 직접 text를 입력해도 출력이 된다.
document.querySelector('#textContent').textContent ='hello textContent';
document.querySelector('#innerText').innerText ='<strong> hello textContent </strong>';
document.querySelector('#innerHTML').innerHTML ='<strong> hello textContent </strong>';
여기서 주의깊게 볼건 innerHTML 은 태그속성을 포함한다는것이다.
innerText 는 strong태그를 그대로 문자열로 반환한다.
728x90
'컴퓨터 정보 > javascript' 카테고리의 다른 글
javascript : forEach 사용하기 (0) | 2022.11.30 |
---|---|
javascript : classList.add / remove를 사용해보자 (0) | 2022.11.30 |
javascript : Spread Operator 배열, 문자열, 객체 등 반복 가능한 객체 (Iterable Object)를 개별 요소로 분리할 수 있습니다. (0) | 2022.11.28 |
javascript : apply = 배열의 값을 인자로 주고 싶을때 사용 (0) | 2022.11.28 |
javascript : Rest operator 뒤에 ... 을 붙혀 여러개의 인자값을 배열로 만들어줌 (0) | 2022.11.28 |