How can I hide an element using Twitter Bootstrap and show it using jQuery?
Toggle visibility in Bootstrap by adding the .d-none
class for hiding. Use jQuery's .removeClass('d-none').show()
to make it visible:
Bootstrap and jQuery: Mastering visibility
Working in harmony, Bootstrap and jQuery offer a suite of tools to control element visibility. Bootstrap utilises .d-none
and .hidden
classes in its 4.x and 3.x versions respectively for making elements disappear. The .invisible
class renders items transparent but space-occupying, as if your elements were ghosting you.
In turn, jQuery comes in with its class manipulating methods to hide and reveal these elusive components:
More ways to manage visiblity
Working with CSS specificity
While using jQuery to alter styles, don't forget the CSS specificity:
This mitigates the usage of !important
thus preventing any heartbreaking specificity wars in your CSS.
Bootstrap: The collapsing method
Looking for a dramatic reveal with a transition effect? Bootstrap's got your back with the .collapse plugin:
Direct visibility management via jQuery
Direct usage of jQuery's .show()
and .hide()
methods can control visibility, but might redefine the term "respect" when it comes to Bootstrap's styling rules:
Custom hiding classes
Think about using a custom CSS class for a personalized hiding act. It can dodge potential overlapping with Bootstrap's styling:
When in doubt, hit the docs
The Bootstrap and jQuery documentation are your holy grail when it comes to updates and best practices. Embrace the habit of referring to them to ensure your code is both efficient and up-to-trend.
Was this article helpful?