본문 바로가기

WEB

[JavaScript] innerText 와 innerHTML 비교하기

innerText VS innerHTML


 

innerText - 문자를 가져올때 html 태그를 문자로 인식

innerHTML - 문자를 가져올때 html 태그를 태그로 인식

 


읽기만하면 잘 이해가 되지 않으니 코드를 보면서 이해하자!!

See the Pen Untitled by Lee-YuGyeong (@lee-yugyeong) on CodePen.

See the Pen Untitled by Lee-YuGyeong (@lee-yugyeong) on CodePen.

innerText는 <a href='https://daum.net'>daum</a>"문자열로 출력한다.

innerHTML은 "<a href='https://daum.net'>daum</a>"를 가져와 태그로 인식하여 다음 바로가기 링크가 생성된것을 볼 수 있다.