Corrected data attribute

This commit is contained in:
Tapas Adhikary 2020-08-16 08:36:31 +05:30
parent a80e245253
commit 01d59620b9
1 changed files with 5 additions and 2 deletions

View File

@ -12,7 +12,7 @@
<script> <script>
function reveal() { function reveal() {
let dataDiv = document.getElementById('data-attr'); let dataDiv = document.getElementById('data-attr');
let value = dataDiv.getAttribute('data-custom-attr'); let value = dataDiv.dataset['customAttr'];
document.getElementById('msg').innerHTML = `<mark>${value}</mark>`; document.getElementById('msg').innerHTML = `<mark>${value}</mark>`;
} }
@ -25,7 +25,10 @@
<img src="../home.svg" alt="home" /> <img src="../home.svg" alt="home" />
</a> </a>
<h2> Know data attribute </h2> <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
class="data-attribute"
id="data-attr"
data-custom-attr="You are just Awesome!"> I have a hidden secret!
</div> </div>
<button onclick="reveal()">Reveal</button> <button onclick="reveal()">Reveal</button>