Created
April 8, 2025 16:48
-
-
Save cferdinandi/30d4bdad7eb4f76047b7c0cc72be684c to your computer and use it in GitHub Desktop.
View the tutorial for this code: https://youtu.be/YCGWNaI8w1E
This file contains hidden or 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 handleClick (event) { | |
// Make sure clicked element has the .save-data class | |
if (event.target.matches('.save-data')) { | |
// Get the value of the [data-id] attribute | |
let id = event.target.getAttribute('data-id'); | |
// Make sure there's an ID | |
if (id) { | |
// Get the user token from localStorage | |
let token = localStorage.getItem('token'); | |
// Make sure there's a token | |
if (token) { | |
// Save the ID to localStorage | |
localStorage.setItem(`${token}_${id}`, true); | |
} | |
} | |
} | |
} |
This file contains hidden or 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 handleClick (event) { | |
// Make sure clicked element has the .save-data class | |
if (!event.target.matches('.save-data')) return; | |
// Get the value of the [data-id] attribute | |
let id = event.target.getAttribute('data-id'); | |
// Make sure there's an ID | |
if (!id) return; | |
// Get the user token from localStorage | |
let token = localStorage.getItem('token'); | |
// Make sure there's a token | |
if (!token) return; | |
// Save the ID to localStorage | |
localStorage.setItem(`${token}_${id}`, true); | |
} |
This file contains hidden or 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 handleClick (event) { | |
// Make sure clicked element has the .save-data class | |
if (!event.target.matches('.save-data')) return; | |
// Get the value of the [data-id] attribute | |
let id = event.target.getAttribute('data-id'); | |
if (!id) return; | |
// Get the user token from localStorage | |
let token = localStorage.getItem('token'); | |
if (!token) return; | |
// Save the ID to localStorage | |
localStorage.setItem(`${token}_${id}`, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment