/data-attribute-styling.html Secret
Created
March 25, 2021 09:35
Star
You must be signed in to star a gist
Using data attributes for modified styling
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
<style> | |
.card { | |
/* Ignore these styles */ | |
width: 20rem; | |
height: 20rem; | |
border: 0.25rem dashed crimson; | |
margin-block-start: 1rem; | |
} | |
.card[data-hidden=true] { | |
display: none; | |
} | |
</style> | |
<script> | |
const toggleVisibility = () => { | |
const cardElement = document.querySelector(".card") | |
const currentVisibility = cardElement.dataset.hidden | |
// currentVisibility will be either `undefined`, `"true"`, or `"false"` | |
cardElement.dataset.hidden = currentVisibility !== "true" | |
} | |
</script> | |
<button onclick="toggleVisibility()">Toggle the card</button> | |
<div class="card"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment