Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to hide the elements using bootstrap classes?

I am trying to do do a small testing using bootstrap, where I want to show h1 only for desktop /large and h2 only for mobile but when I use the following , both h1 and h2 show-up on all screens .

h1 and h2 is input element and writing condition depending on whether they are filled or not.

if(h1 != null){
<h1 class="d-none d-lg-block d-xl-none"> Test 1</h1>
}
else{
<h2 class = "d-block d-sm-none"> Test 2 </h2>
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No need for the conditional statement, Bootstraps display properties should work fine for you.

You only need the . if you are specifying the class outside the markup in CSS or JS for example.

You can use d-xl-block on h1 for it show over 1140px (desktop). Then just use d-xl-none on the h2's since you don’t want them to be present when h1 is showing.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

<h1 class="d-none d-xl-block">Test 1</h1>

<h2 class="d-block d-xl-none">Test 2</h2>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading