mobile navigation menu remains open after selecting a link

When the Fixed-to-top navbar is used in mobile view, such as clicking a Navbar icon, it does not collapse afterward while the page is loading. How can I prevent the page from loading in the navbar section?

Here is the link to my website:

CLICK HERE

Additionally, this is my JavaScript code:

JavaScript Code

// Anchors Position
                $('[data-hash]').on('click', function(e) {
                    e.preventDefault();

                    $('body').addClass('scrolling');
                    var target = $(this).attr('href')
                        delay = 0;

                    if($(document).scrollTop() == 0) {
                        $(document).scrollTop($('#header').height());
                        delay = 200;
                    }

                    setTimeout(function() {

                        if ($(window).width() < 991 && $('.nav-main-collapse').hasClass('in')) {
                            $('.nav-main-collapse').collapse('hide');
                            self.scrollToTarget(target);
                            return this;
                        }

                        self.scrollToTarget(target);

                    }, 200);



return this;
            });

            return this;
        },

Below, I have attached a screenshot for reference:

Screenshot

Answer №1

Include the attribute type="button" in the following button:

<button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse"><i class="fa fa-bars"></i></button>

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

Alignment of text in a stationary element's location

I'm working on implementing a feature for an online shop where new items are added to the cart, and I want to display the number of new items added. However, I am facing a challenge in centering the text that displays the number, especially when the n ...

Setting up a reverse proxy for deploying React applications

I am attempting to implement a setup where multiple containerized SPAs are deployed using a reverse proxy for routing. Each container contains a production build create-react-app served by an express app with the following configuration: app.use(express.s ...

What could be causing my closing tag to abruptly end the section tag?

I encountered an issue that says the 'section' is closed by another tag. Upon reviewing my HTML code, everything appears to be correct. <ng-container *ngIf="display$ | async as display"> <section [class.open]="display ...

Comparing elements within one array to those in another array

I am working with two arrays containing different data sets array1 = [{id:"1",title:"Writing"},{id:"2",title:"Singing"},{id:"3",title:"Dance"}]; array2 = [{tags: "1",title: "USA",type: "text"}, {tags: "1,2,3",title: "Japan",type: "image"}, {tags: "2,3",t ...

Utilizing Bootstrap 4 to Position an Image Amidst Two Card Elements

Looking at the bootstrap 4 card documentation page in the Images > Image Caps section, you'll find two examples provided. In these examples, the image can be positioned either at the top or the bottom of the card block, with the .card-block div eit ...

Aligning the right menu of Ant Design from the Layout component

How can I align the menu to the right in antd? https://i.sstatic.net/xmh6E.png Please Note: The image has been edited using Photoshop and is not real. I attempted to declare a className = "Menu" and set .Menu {align-items: right;} but it didn't wor ...

Is it feasible to generate a realistic arrow using CSS and then rotate it?

Can a fully functional arrow be created using CSS alone? Here is the method I used to create just the arrowhead: http://jsfiddle.net/2fsoz6ye/ #demo:after { content: ' '; height: 0; position: absolute; width: 0; border: 10p ...

What is the Dojo counterpart for jQuery's .live() function?

Is there a Dojo alternative to jQuery .live() function? http://api.jquery.com/live/ In my search, the only workaround I came across was to disconnect the event handlers in Dojo and then reconnect them when new dynamic content is added to the page. ...

Set the CSS table to have a width of 100% and ensure that the table data cells have hidden

My table has a 100% width, and some of the td elements have overflow hidden. I want to make their text appear as ellipsis when it's too long. I can achieve this with fixed td sizes, but I need them to be relative to the content. This question was fi ...

Unable to position a div alongside a fluid div with minimum and maximum widths

Within this container, there is a div. #leftBanner { height: 100%; background-color: #CCC; width: 22%; min-width: 245px; max-width: 355px; float: left; } This particular div doesn't cooperate when I try to float another div next to it. While I could ...

My website is currently being hosted on Github, but I am experiencing issues with the CSS. I keep getting an error message saying "Failed to load resource: the server responded

view image here I recently uploaded my website on Github and am facing an issue with the CSS file not working properly. Can someone please help me troubleshoot this problem? website link Github repository I have reviewed the links connecting the HTML t ...

Middle-Click JavaScript Action

On the website I'm currently working on, there is a button that uses a sprite sheet animation and therefore needs to be set as a background image. I want the button to have a slight delay when clicked, so the animation can play before redirecting to a ...

Efficiently encode and decode JSON data between PHP and JavaScript

I am attempting to convert my array results into JSON format and then transmit them to an AJAX success event using JavaScript. PHP $results = array( "time1" => 1, "time2" => 2, ); echo json_encode($results); JAVASCRIPT ...

Jquery removes brackets from data following an ajax request

My data text file looks like this: [[1412525998000,"91.83"],[1412525998000,"91.83"],[1412525997000,"90.14"]...ETC However, when I receive this data via an ajax request, something strange happens. The 'data' variable turns into this: 1412525998 ...

Show button once modal has been closed

I have a 'start' button that triggers a modal window with an embedded video. Once the user closes the modal, I want to show a 'redeem' button after a delay of 6 seconds. HTML: <a id="video-start" onclick="openVideoModal()"><i ...

Using JavaScript, swap out the default "item added to cart" message with a custom Sweet Alert notification in WooCommerce

After removing the standard "Added to cart" message provided by WooCommerce, I have implemented a new code snippet using Sweet Alert. The goal is to eliminate all default "added to cart" messages and exclusively use the Sweet Alert feature. Although my co ...

JavaScript's functionality akin to PHP's exec() function

I am searching for a way to run a shell command through javascript, similar to the functionality of PHP's "exec()" function. I understand that executing shell commands in javascript may not be recommended due to security concerns. However, my javascri ...

What is the best way to show search results in real-time as a user

While working on a search box feature that filters and displays results as the user types, I encountered an issue where the search results keep toggling between showing and hiding with each letter input. As a beginner in JS, I am hoping for a simple soluti ...

What methods can be used to validate an undefined value?

exploding right now if (myObject.myKey.myThing){ } undefined myThing cannot be read What approach can be taken to determine if myThing is defined before entering the if block? ...

Tips for customization: Altering HTML table borders and column widths

I am looking to update the appearance of an HTML table. Currently, it looks like this: https://i.sstatic.net/pueyW.png Here is the code snippet: <div className="student-schedule"> <table className="student-calendar-table" ...