mddanishyusuf / dailyhack

🐱‍💻 Tiny Tiny Hacks we use in our daily life.
https://dailyhack.now.sh/
149 stars 15 forks source link

Easily change state of HTML elements using Class names. #80

Closed qasim2020 closed 1 year ago

qasim2020 commented 5 years ago

Use CSS class names to easily change stuff on your websites. It keeps code cleaner and builds your CSS-vocabulary over time. For example toggling display of an element:-

CSS

d-none : {
display: none !important;
}

d-block : {
display: block !important;
}

HTML

<div id="error-msg">
This is may be some error message on your form.
</div>

jQuery

$('#error-msg').toggleClass('d-none d-block');

Example

Here is a code pen to make popular collapsing navbar. Toggle between class names .collapse and .collapsing using jQuery. https://codepen.io/qasim_ali/pen/wbLpPG

Additional Uses

so many possibilities, it helped me a lot. I picked this convention from bootstrap.

qasim2020 commented 5 years ago

@mddanishyusuf can you please check if it is valid and push it to dailyhacks. Thanks.

Qasim here.