jasonbutz.info

Bootstrap v4 Responsive Navbars without jQuery

JavaScript, Bootstrap

I’ve been using Bootstrap v4 in a project I am working on for a friend. He wants to be able to use the application on a mobile phone. Since I used Bootstrap’s navbar, I was going to need Bootstrap’s collapse javascript code. That code depends upon jQuery, and that is an issue for me. So I decided I would write some code that would perform the same basic function as Bootstraps, but not use jQuery at all.

So long as the collapsing is vertical, and you don’t need the events or the programmatic console this should work just fine for you.

Here is a small demo of the code in use.

See the Pen Bootstrap 4 Collapsable Navbar, without jQuery by Jason Butz (@jasonbutz) on CodePen.

And the code in a gist, just because.