mirror of
https://github.com/atapas/html-tips-tricks.git
synced 2024-11-16 00:38:26 +01:00
done with data attribute
This commit is contained in:
parent
0fe838e401
commit
43ed7ecc3a
3 changed files with 39 additions and 0 deletions
31
data-attribute/index.html
Normal file
31
data-attribute/index.html
Normal file
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<li>
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||
<title>HTML Tips and Tricks - Data Attribute</title>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<link rel='stylesheet' type='text/css' media='screen' href='../main.css'>
|
||||
|
||||
<script>
|
||||
function reveal() {
|
||||
let dataDiv = document.getElementById('data-attr');
|
||||
let value = dataDiv.getAttribute('data-custom-attr');
|
||||
document.getElementById('msg').innerHTML = `<mark>${value}</mark>`;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="demo">
|
||||
<h2> Know data attribute </h2>
|
||||
<div class="data-attribute" id="data-attr" data-custom-attr="You are just Awesome!"> I have a hidden secret! </div>
|
||||
<button onclick="reveal()">Reveal</button>
|
||||
|
||||
<br/>
|
||||
|
||||
<p id="msg"></p>
|
||||
</div>
|
||||
</body>
|
|
@ -28,6 +28,10 @@
|
|||
<a href='./mark/index.html'>
|
||||
Mark Content</a> - Highlight things
|
||||
</li>
|
||||
<li>
|
||||
<a href='./data-attribute/index.html'>
|
||||
Custom Data</a> - Data with elements
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
|
4
main.css
4
main.css
|
@ -41,3 +41,7 @@ li {
|
|||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.demo .data-attribute {
|
||||
padding: 10px;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue