Created
August 26, 2022 10:19
-
-
Save shubhamt619/79f67c91513809049e44fa427072ffb0 to your computer and use it in GitHub Desktop.
data-attribute-vanilla-javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printAge(studentId) { | |
// Get the <li> which is clicked | |
let studentListItem = document.querySelector(`[data-id="${studentId}"]`); | |
// Get the age from the data attribute 'age' | |
let age = studentListItem.dataset.age; | |
// Finally log it to console, Duh ! | |
console.log('Age of the clicked student is ', age); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment