Issue with transitioning from Bootstrap 2 to Bootstrap 3 navbar

I am facing an issue with my navbar that collapses perfectly. However, when using the script below to automatically hide the menu upon clicking a menu item:

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    $('.navbar-collapse.in').removeClass('.in').css('height', '0');                     
});

This method worked flawlessly in BS2. But now, the menu is not closing completely anymore and I have to click the toggle button twice to open it again. The difference can be subtle, but if you look closely at the bottom of the second image.

Menu before closing:

https://i.sstatic.net/tXeb8.png

Menu after closing:

https://i.sstatic.net/C1ZSu.png

The HTML structure:

<nav class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
        <a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </a>
    </div>

    <div class="collapse navbar-collapse">
        <ul id="myTab" class="nav navbar-nav">
            <li class="active"><a href="#tab1" data-toggle="tab">Tab1</a></li>
            <li><a href="#tab2" data-toggle="tab">Tab2</a></li>
            <li><a href="#tab3" data-toggle="tab">Tab3</a></li>
            <li><a href="#tab4" data-toggle="tab">Tab4</a></li>
            <li><a href="#tab5" data-toggle="tab">Tab5</a></li>
            <li><a href="#tab6" data-toggle="tab">Tab6</a></li>
            <li><a href="#tab7" data-toggle="tab">Tab7</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#tab8" data-toggle="tab">Tab8</a></li>
        </ul>
    </div>
</nav>

Answer №1

attempt:

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
       $('.navbar-collapse').collapse('toggle');                    
}); 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The data being sent from Ajax to the controller is not successfully transmitting the value to the controller

I've encountered issues trying to pass JSON data into an MVC controller. In the controller method, the property is defined as newObject like this: [HttpPost] public ActionResult Create(NewObject newObject) { try { //_deviceMangemen ...

Adjust the size of the child div to fit the remaining space within the parent div

I'm dealing with a situation where there are two child divs inside a parent div. The first child div takes up 32% of the width, while the second child div takes up 68% of the width. If I were to set the display of the first child div to "none", how ca ...

Using jQuery to toggle the visibility of select options for multiple elements

Hey there, I've got this code snippet that effectively shows and hides elements based on a selected option. It works well with one element, but when I try to use it with multiple elements, it doesn't function correctly. How can I tweak it so that ...

Storing multiple values of dynamically added elements in a single variable and accessing them within a function

Is it possible to store multiple values into a single variable and then access them in a setTimeout function? $(document).ready(function (){ div ({'div':'#noo','auto':'true','pos':'top',' ...

display:none !important style elements shown (jQuery)

According to the jQuery documentation on .show() A reminder: If you are using !important in your styles, like display: none !important, you will need to override this style by using .css('display', 'block !important') if you want ...

Conditionally displaying an input model in Vue.js using v-if

Just starting to learn vue.js and I'm looking to display table data. My idea is that when the table is in display mode, it should only show the data. However, when I click on the edit button of a table row, I want that specific row to switch to edit m ...

What is the best method for choosing all children's text except for a specific tag in Selenium's XPath selector?

Here is the HTML code I am working with: <div id="content"> <h1>Title 1</h1><br><br> <h2>Sub-Title 1</h2> <br><br> Description 1.<br><br>Description 2. <br><br ...

Issues following compilation with npm run prod

I am currently working on a small website using Laravel and Tailwind CSS on shared hosting. While I am able to use a command line tool on the host, I have encountered an issue. In my local environment, Tailwind works perfectly fine. However, after running ...

What is the best way to fetch images from a JSON object in a React application?

I have been trying to load images from an array of objects in React, but I keep encountering a "module not found" error. This issue has been frustrating me for the past couple of days. Can someone please help me troubleshoot this problem or provide some su ...

Format specific words or characters in a text input

In HTML, when I want to display strings in a Text Input or TextArea, I am looking for a way to have specific substrings render with a box around them. I envision these boxed substrings as being treated as a single entity, similar to how highlighting or tex ...

Is there a way for me to determine if something is hidden?

My goal is to have selector B toggle when selector A is clicked or when clicking outside of selector B. This part is working fine. However, I'm struggling with preventing selector B from toggling back unless selector A is specifically clicked - not w ...

jQuery: Assigning a unique ID to every selected element

Currently, I am developing an 'inline translator' software designed for a cloud computing platform in order to expand language options beyond what is supported. The core functionality of this application relies on jQuery to identify text content, ...

Replace the typical bootstrap text class with stylish and modern google material icons

As a newcomer to the world of javascript, I acknowledge that my approach may not be ideal... I'm attempting to modify the color of a material icon upon clicking it. Essentially, I want to toggle it on and off. The challenge lies in the code's in ...

Why does Javascript Tic-Tac-Toe delay notifying the user until the entire board is full?

There have been a lot of questions about Tic-Tac-Toe javascript, but my issue is unique. My code works fine, but it doesn't declare a winner or a tie game until the entire board is filled. I suspect that my if statements are causing problems and can&a ...

Animate CSS during page load

Currently, I am implementing AJAX to dynamically load pages on my website. During the loading process, I wish to incorporate a spinning animation on the logo to indicate that content is being fetched. The jQuery script (although I'm still learning an ...

What is the easiest way to modify the color of a basic PNG image in a web browser?

While working on a website project, I encountered instructions for mouseover styles in the design that got me thinking: It's straightforward to achieve with javascript or css image swapping... but here's the catch. There will be multiple icon li ...

Issue encountered while incorporating a PHP file into Javascript code

I'm facing a particular issue where I have a PHP file that is supposed to provide me with a JSON object for display in my HTML file. Everything seems to be working fine as I am receiving an output that resembles a JSON object. Here's the PHP file ...

Achieving Centered Items with CSS Flexbox and Positioning

Struggling to arrange 3 elements using flexbox while keeping them centered both horizontally and vertically. Here is the desired layout: https://i.sstatic.net/Uo6WS.png This is my current attempt, but it's not working as expected. Can anyone spot t ...

Tips on retrieving JavaScript output within an AngularJS model

When I bind the result date to an input text based on the input id, the input value is not saving in the ng model of Angular script. <input type="text" class="form-control" maxlength="10" ng-model="EmployeeSave.HijriDate" onclick="showCal2();" ...

The functionality of CSS Inline Block display is not displaying inline as expected

I have the following HTML and CSS code, but I am having issues getting the dropdown to display inline. .project Type{ display: inline-block; } <form class="smart-form"> <div class="row"> <div class="col col-sm-6 col-md-2 col-lg- ...