1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Data Attributes</title>
<style>
div {
width: 300px;
height: 300px;
background-color: red;
margin-bottom: 50px;
}
div[data-display-name='apple'] {
background-color: yellow;
}
</style>
</head>
<body>
<div data-index="1" data-display-name="apple"></div>
<div data-index="2" data-display-name="banana"></div>
<span data-index="1" data-display-name="strawberry">Hi there</span>
<script>
const fruit = document.querySelector('div[data-display-name="apple"]');
console.log(fruit.dataset);
console.log(fruit.dataset.displayName);
console.log(fruit.dataset.index);
</script>
</body>
</html>
Data Attributes (유용한 Data-)
This post is licensed under CC BY 4.0 by the author.