오늘은 HTML5에서 새롭게 추가된 Dataset에 대해서 알아보겠습니다.
Dataset은 HTML에 추가의 커스텀 속성을 표시하는 데 표준화된 방법을 제공하기 위해 제안되었습니다.
"data-*" 어트리뷰트로 표기하며, HTML5 표준 속성처럼 접근할 수 있습니다.
<article
id="electric-cars"
data-columns="3"
data-index-number="12314"
data-parent="cars">
…
</article>
const article = document.querySelector("#electric-cars");
// const article = document.getElementById("electric-cars")
article.dataset.columns; // "3"
article.dataset.indexNumber; // "12314"
article.dataset.parent; // "cars"
article[data-columns="3"] {
width: 400px;
}
article[data-columns="4"] {
width: 600px;
}