When you click on either the Main menu or the Search box in the image, only one menu should open at a time while the other closes

View the image of how the menu looks when both menus are opened.

When clicking on each menu separately, both menus appear instead of closing one when the other is clicked. How can I achieve this?

 $('.toggle-sm-nav, .js-toggle-sm-navigation').click(function(){

        // Change button
        $(this).children('span').toggleClass('glyphicon-align-justify icon-close-menu-cross2');
        $('.sm-searchboxc').find('i').removeClass('active');

        // Toggle menu on hamburger
        $('.navcontainer').toggle();
        $('.header-nav-container').toggleClass('brgropen');

        if( $('.header-nav-container').hasClass('brgropen') ){
            $('body').css('overflow', 'hidden');
        } else {
            $('body').css('overflow', 'visible');
        }
    });
        // Focus search field when opened
        $('.js-toggle-xs-search').on('click', function(){
            $('.sm-searchboxc input#search').trigger('touchstart');

        });
        $('.sm-searchboxc input#search').on('touchstart', function(){
            setTimeout(function(){
                $('.sm-searchboxc input#search').focus();
            }, 0);    
       });

The HTML Code is provided below.

<div class="sm-navigation">
                <div class="row">

                    <div class="sm-nav col-xs-1 col-sm-1 visible-sm">
                        <button class="btn btn-default js-toggle-sm-navigation toggle-sm-nav btn-sm" type="button">
                            <span class="glyphicon glyphicon-align-justify"></span>
                        </button>
                    </div>

                    <div class="col-xs-12 col-sm-2 col-md-2 logocontainer">
                        <div class="site-logo">

                            <div class="content"><a href="/"><img src="/_ui/responsive/theme-blue/images/abc.svg"></a></div></div>
                    </div>

                    <div class="xs-nav col-xs-3 col-sm-3 visible-xs">
                        <button class="btn btn-default js-toggle-sm-navigation" type="button">
                            <span class="glyphicon glyphicon-align-justify"></span>
                        </button>
                    </div>

                    <div class="xs-store-finder col-xs-3 visible-xs ">
                        <a href="/store-finder">
                            <button class="btn btn-default btn-sm" type="button">
                                <span class="glyphicon icon-store-locator"></span>
                            </button>
                        </a>
                    </div>

                    <div class="xs-search col-xs-3 visible-xs">
                        <button class="btn btn-default js-toggle-xs-search toggle-xs-search btn-sm" type="button">
                                <span class="glyphicon icon-search"></span>
                            </button>
                        </div>

                    <div class="searchboxc md-searchboxc col-xs-12 col-sm-5 col-md-5 hidden-xs hidden-sm">
                        <div class="site-search ui-front">
    <form id="search-form" name="search-form" method="get" class="search-form ng-pristine ng-valid ng-scope ng-valid-maxlength" ng-submit="search.submit()" ng-controller="SearchController as search" action="/search/">

The image can be seen below. When clicking on each menu separately, both menus will display instead of closing one when the other is clicked. How can this functionality be achieved?

Answer №1

Could it be that you placed your 'on-click search function' within the navigation on-click function?

$('.js-toggle-xs-search').on('click', function(){

This way, whenever the navigation is clicked, so is the search function triggering as well.

$('.toggle-sm-nav, .js-toggle-sm-navigation').click(function(){

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

Shopping cart feature in PHP - Ajax response only functioning once

I'm in the process of developing a shopping cart. I start by adding products to the cart, then use Ajax to dynamically update the quantity when it changes. Everything works smoothly after the first change, but subsequent quantity updates do not refres ...

``Incorporating flowplayer with autoplay set to true has proven to be ineffective

Is there a way to get my PHP website to automatically play videos using flowplayer? I'm having trouble getting it to work and no errors are being shown. $(function(){ // Top Stories videos var topStoriesVideos = [ { so ...

Unable to make getJSON function properly with CodeIgniter

I'm experimenting with using getJSON to retrieve the most recent data from my database. So far, I've stored it in an array and used json_encode(the array). This method successfully displays the information on the view, but the problem lies in the ...

Create a duplicate of the table and remove specific rows

Hi there, I have a query about duplicating a table. I am looking to extract specific results and display only those results. To illustrate, here is an example in HTML code: <table class="table table-striped" id="ProfileList2"> <tbody> ...

display dynamic graphs using json data from a php backend

I'm having trouble displaying a graph using JSON data in Highcharts. Here is a sample of what I need: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/column-rotated-labels/ The file values ...

Adjust the formatDate function in the Material UI datepicker

I recently implemented the material-ui datepicker component with redux form and it's been working great. However, I have encountered a minor issue. Whenever I change the date, it displays in the input field as yyyy-mm-dd format. I would like it to app ...

Implementing Dynamic Checkbox Selection using JavaScript

Could someone please assist me with this coding challenge? HTML <div id="toggle"> <ul> <li class="active"><input type="checkbox" id="test" value="2014" name="test" checked/> 2014</li> <div style="display:block;" id ...

How can Play framework be used to display static HTML pages with static JavaScript and CSS files?

I'm currently exploring options for rendering or routing to static web apps stored in the Play's public folder. Here is my project structure: myapp + app + conf + modules + public | + webapp1 | + css | + ...

Chat box custom scrollbar always positioned at the bottom

I have a personalized chat box where I included overflow-y for scrolling functionality. However, every time I input a message in the text box, it displays at the top of the scrollbar window. Is there a way to automatically show the most recent message I ...

Unable to view newly added components

I am currently in the process of setting up a website, focusing on arranging and formatting everything on the page before moving on to styling and adding JavaScript. I recently added three div tags after my form to create three separate columns in the ne ...

Implementing Javascript to insert IFRAME into the DOM

I'm looking to incorporate an iframe into my webpage. The iframe needs to link to a specific URL. I attempted to add the following code to my HTML, but it's not functioning as expected: document.createElement('<iframe src='http://ex ...

An easy guide to using Vue-Router to manipulate URL query parameters in Vue

I'm currently working on updating query parameters using Vue-router as I change input fields. My goal is to adjust the URL query parameters without navigating to a different page, but only modifying them on the current page. This is how I am approachi ...

Is there a way to apply -webkit-line-clamp to this JavaScript content using CSS?

i have a random-posts script for my blogger website <div class="noop-random-posts"><script type="text/javascript"> var randarray = new Array(); var l=0; var flag; var numofpost=10; function nooprandomposts(json){ var total = ...

Developing an SQL table for a website using JavaScript

My command is not functioning as expected and I am struggling to identify the issue. The database opens successfully, however, it fails to process the table creation. var createtable2 = 'CREATE TABLE IF NOT EXISTS offlineCabinDefects (id INTEGER PRIM ...

Arranging CouchDB/Couchbase view based on the quantity of keys

Looking to create a view that displays the top 10 tags used in my system. While it's simple to get the count using _count in the reduce function, the list is not sorted by the numbers. Is there a way to accomplish this? function(doc, meta) { if(doc ...

Learn how to retrieve the HTTP headers of a request using AngularJS

When working with AngularJS, I know that accessing an HTTP request's GET parameters is easy using: $location.search().parameterOfInterest But how can I access the HTTP headers of the request? It's worth noting that I'm not utilizing $http ...

My basic HTML site is displaying incorrectly on Firefox, Safari, and IE

I have recently built a basic website using HTML and CSS. After developing it primarily on Chrome, I've noticed that the layout is not rendering correctly on Firefox, Safari, and Internet Explorer. There are issues with the alignment of tags and butt ...

Creating JavaScript Objects from HTML Form data with the help of serializeJSON

Struggling extracting HTML form data into the required JSON format for server communication. Despite following a guide, I can't get the output right. Managed to extract question keys and values, but labeling is tricky. Current Output: {"Question1":" ...

I am experiencing difficulties with decoding the JSON in Appengine ProtoRPC

For some reason, I'm having trouble getting the protoRPC API to work on my app-engine. Here is the request I am making: $.ajax({ url: '/guestRPC.get_tags', type: 'POST', contentType: 'application/json', ...

Issue with loading a Mongoose model

I'm facing a strange problem with NodeJS, require function, and mongoose. I have defined a user model schema as follows: let mongoose = require('mongoose'); let Schema = mongoose.Schema; let depositSchema = new Schema({ customer: Stri ...