<input type="text" value="Hello" id="myInput">
// 요소 선택
let input = document.getElementById('myInput');
// Attribute 값을 가져오기
console.log(input.getAttribute('value')); // "Hello"
// Attribute 값을 설정하기
input.setAttribute('value', 'New Value');
<input type="text" value="Hello" id="myInput">
// 요소 선택
let input = document.getElementById('myInput');
// Property 값을 가져오기
console.log(input.value); // "Hello" (초기 HTML value 값)
// Property 값을 설정하기
input.value = 'New Value'; // input 요소의 값이 'New Value'로 변경됨
<input type="text" value="Hello" id="myInput">
------
let input = document.getElementById('myInput');
// Attribute와 Property의 차이 확인
console.log(input.getAttribute('value')); // "Hello" (HTML 특성 값)
console.log(input.value); // "Hello" (초기 값이 동일)
// Property 값을 변경
input.value = 'Goodbye';
console.log(input.getAttribute('value')); // 여전히 "Hello" (변경되지 않음)
console.log(input.value); // "Goodbye" (변경됨)
// Attribute 값을 변경
input.setAttribute('value', 'New Value');
console.log(input.getAttribute('value')); // "New Value" (변경됨)
console.log(input.value); // 여전히 "Goodbye" (property는 그대로)
eslint 사용 안하기 (0) | 2024.09.18 |
---|---|
importmap - type attribute 타입속성 (3) | 2024.09.18 |
canvas.toDataURL() (3) | 2024.09.16 |
property accessors, dot notation, bracket notation, 점 표기법, 대괄호 표기법, 속성접근자 (0) | 2024.09.16 |
OpenCV, openCV.js (3) | 2024.09.16 |