본문 바로가기
STUDY/JavaScript

[JavaScript] 속성값 제어 Element.setAttribute()

by bottlesun 2022. 11. 27.
728x90

Element.setAttribute()

지정된 요소의 속성 값을 설정한다. 속성이 이미 있는 경우 값이 업데이트가 된다.
그렇지 않으면 지정된 이름과 값으로 새 속성이 추가된다.

사용 방법

Element.setAttribute("className", "클래스명");
Element.setAttribute("id", "아이디명");
Element.setAttribute("name", "이름");
Element.setAttribute("href", "#");
728x90

댓글