본문 바로가기

Web/JavaScript

[Mozilla WEB API] HTMLElement: dataset property

728x90

 

 

dataset 은 사용자 정의 데이터 속성으로 HTMLElement 읽기/쓰기 액세스를 제공한다.

 

 

An HTML data-* attribute and its corresponding DOM dataset.property modify their shared name according to where they are read or written:In HTML

The attribute name begins with data-. It can contain only letters, numbers, dashes (-), periods (.), colons (:), and underscores (_). Any ASCII capital letters (A to Z) are converted to lowercase.

In JavaScript

The property name of a custom data attribute is the same as the HTML attribute without the data- prefix, and removes single dashes (-) for when to capitalize the property's "camel-cased" name.

 

 

 

 

속성 설정 후에는 값은 String 이고, 

예를 들어 element.dataset.sample = null 이여도 data-sample="null"로 변환된다

제거하려면 

delete element.dataset.sample;

 

728x90