Why is my navbar collapsing too fast?

Hello everyone, I’m new in coding and I would like to know if there is something wrong in my code because as soon as I click on the hamburger menu it opens and closes in a second…

<nav class="navbar navbar-expand-lg navbar-light  bg-light sticky-top ">
	<div class="container">
	
	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive">
		<span class="navbar-toggler-icon"></span>
		</button>
		
	<div class="collapse navbar-collapse" id="navbarResponsive">
		<ul class="navbar-nav ml-auto">
			<li class="nav-item"><a href="index.html" class="nav-link active">Početna</a></li>
			<li class="nav-item"><a href="yoga.html" class="nav-link">Yoga</a></li>
			<li class="nav-item"><a href="fitness.html" class="nav-link">Fitness</a></li>
			<li class="nav-item"><a href="biciklizam.html" class="nav-link">Biciklizam</a></li>
			<li class="nav-item"><a href="onama.html" class="nav-link">O nama</a></li>
			<li class="nav-item"><a href="cjenik00.html" class="nav-link">Cjenik</a></li>
		</ul>
		</div>
	</div>
	</nav>
	
<!-- End Navigation -->

thank you in advance :slight_smile:

Hi @KarlaJokic welcome :slight_smile: . Do you have the link to your website that’s causing the problem? I can take a look for you in there if you like.

If you know anyone who can see the error in the code I would be grateful. You can’t open the link because its not published yet on any hosts.

1 Like

I just dropped your code into a bootstrap template and it works out of the box.

There must be something else in your page affecting it.

2 Likes

Yep something extra must be in that box that is causing it not to work on your website.

Try copying the code @PaulOB just shared here back to your website, reload and try it again.

I just copy pasted my whole page code to your Bootstrap4 hamburger and it worked without an error… I can only hope it will work when live.

I assume you have all the correct bootstrap css,js and jquery files in your local version?

2 Likes

Quick guess is you have a trigger somewhere in your custom JS which is resetting the collapse class on the navigation.

The data-toggle on the button tells you which class is getting added/removed when the button is pushed. So if it’s re-appearing, it’s likely that you’ve got a trigger somewhere that is resetting it - possibly something intended to run at document load which is running at another time.

2 Likes

yes!
found it in JS, now resolved
thank you so much! :smile: :smile:

3 Likes

Glad you got it worked out :smiley:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.