본문 바로가기

자바스크립트

[JavaScript] value VS. textContent

document.querySelector('.guess').value = '' 
document.querySelector('.guess').textContent = ''
  • Only input elements have a "value". It represent the input data supplied by the user or provided initially by the code. Whereas textContent property sets or returns the text content of the specified node, and all its descendants.
  • 오직 Input elements만 value를 가진다. 다른 elements는 textContent로 수정하면 된다!
  • textContent returns the concatenation of the textContent of every child node, excluding comments and processing instructions and if if the node has no children then textContent will be empty string.

value를 가진 elem은 'input' data type밖에 없다. 여기서 'class = guess'가 input 데이터타입이었음.