After making a selection from the list, I would like to automatically close the select menu

 <div class="topnav__menu">
            <button
              class="
                topnav__button topnav__button--has-arrow topnav__menu-button
              "
              type="button" id="hideselectOption"
            >
              <span class="topnav__button-label">Selection:</span>
              <span class="topnav__button-title" style="text-transform: uppercase !important;">{{selection}}</span>
              <span class="topnav__button-arrow"
                ><svg width="7px" height="5px">
                  <path
                    d="M0.280,0.282 C0.645,-0.084 1.238,-0.077 1.596,0.297 L3.504,2.310 L5.413,0.297 C5.770,-0.077 6.363,-0.084 6.728,0.282 C7.080,0.634 7.088,1.203 6.746,1.565 L3.504,5.007 L0.262,1.565 C-0.080,1.203 -0.072,0.634 0.280,0.282 Z"
                  />
                </svg>
              </span>
            </button>
            <div class="topnav__menu-body" >
              <span class="topnav__menu-item" ng-click="makeSelection('item1')">
                <img src="public/assets/images/icons/item1.png" alt="" />
                <span>Item 1</span>
              </span>
              <span class="topnav__menu-item" ng-click="makeSelection('item2')">
                <img src="public/assets/images/icons/item2.png" alt="" />
                <span>Item 2</span>
              </span>
              <span class="topnav__menu-item" ng-click="makeSelection('item3')">
                <img src="public/assets/images/icons/item3.png" alt="" />
                <span>Item 3</span>
              </span>
              <span class="topnav__menu-item" ng-click="makeSelection('item4')">
                <img src="public/assets/images/icons/item4.png" alt="" />
                <span>Item 4</span>
              </span>
              <span class="topnav__menu-item" ng-click="makeSelection('item5')">
                <img src="public/assets/images/icons/item5.png" alt="" />
                <span>Item 5</span>
              </span>
            </div>
<script>

     $(function() {
        $('.option--trigger--click .option__button').on('click', function(event) {
            event.preventDefault();

            const choices = $(this).closest('.option');

            if (choices.is('.option--open')) {
                choices.removeClass('option--open');
            } else {
                choices.addClass('option--open');
            }
        });

        $(document).on('click', function (event) {
            $('.option')
                .not($(event.target).closest('.option'))
                .removeClass('option--open');
        });
    });


    $(function() {
        $('.topnav__menu-button').on('click', function() {
            $(this).closest('.topnav__menu').toggleClass('topnav__menu--open');
        });

        $(document).on('click', function (event) {
            $('.topnav__menu')
                .not($(event.target).closest('.topnav__menu'))
                .removeClass('topnav__menu--open');
        });
    });
   </script>

Answer №1

Feel free to include the following code snippet:

function updateLanguage () {
    // Update language logic here...
    document.querySelector(".topbar__menu-body").style.display = "none";
}

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

What is the best way to transfer Flow type properties from one React component to another?

I'm in the process of developing a component that will wrap another component known as Button. The tricky part is that the library where Button is defined does not expose the type of its properties. In order to properly assign types to my component, ...

Issue with the loading order of jQuery in Internet Explorer 9

My webpage heavily relies on jQuery for its functionality. While it works perfectly on most browsers, I am encountering issues specifically with IE9 due to the slow loading of JavaScript. The main problem lies in IE9 mistakenly thinking that JavaScript is ...

Injecting live data into an input field within a table using Angular 4

Trying to create a dynamic row table with input fields in all cells. The loaded data is static, and I'm facing issues adding more data in the view. However, the functionality to add and delete rows is working fine. I have experimented with ngModel and ...

What is the best way to send an imported component as a prop?

Is it possible to pass a component as a prop from the parent to a child component without directly importing it into the child? Parent Component: <template> <ChildComponent :component="componentName"> </template> <script> impo ...

Using Node.js and Typescript to bring in external modules from

Attempting to generate a random integer between 1 and 6 using the 'random' library. Here's what I have coded so far: import random from 'random' function rollDice(min:number, max:number) { return Math.floor(Math.random() * (ma ...

Uniquely tag an uploaded file

My code for uploading files is as follows: var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.open("POST", requestUrl, true); xhr.send(f); I want to draw your attention to the fact that I have attached a l ...

The Bootstrap tabs are not correctly displaying the content

Hey there, I'm currently working on a project that involves using bootstrap tabs (BS4) within a form. One of the requirements is to have forward and back buttons for form navigation, and I'd like to leverage BS4's tab('show') fun ...

The transparency level of materials in THREE.js

When using the lambert shader, I encountered an issue with setting the material. In the example provided, it sets the material as follows: this.material.uniforms.emissive.value = new THREE.Color( Math.random(), Math.random(), Math.random()); Prior ...

The stateless components' onClick event that manages a prop within the Component

My concern lies with a stateless component named EmailItem: I aim to assign it a new prop via a function when clicked. <EmailItem key={i} onClick={// the onClick function here} emailData={email} read={false} /> The desire is for the value of the rea ...

Retrieving selected item values in Angular 2 using ng2-completer

Recently, I decided to experiment with a new autocompleter tool that is unfamiliar to me: https://github.com/oferh/ng2-completer. I successfully imported it and it seems to be functioning properly. My current goal is to retrieve the values of the selecte ...

The Vue method is failing to properly send data to an array of objects

Trying to troubleshoot this issue is proving to be quite challenging for me. Despite following all the guidelines, I seem to be stuck at a roadblock and cannot figure out what is causing the problem. Let's take a look at my vue.js application: new Vu ...

Utilize jQuery Function on Identical Class of <ul> Elements

I have integrated a listview control in my ASPX page. The data is being fetched from the database and displayed in the listview. I have also utilized jQuery script to implement the .fadein() and .fadeout() effects on the listview elements. However, when I ...

How can I adhere to Angular 2's naming convention for Input and Output as suggested by the styleguide?

Working with inputs and outputs while following Angular 2's styleguide naming convention Initially, my directive was defined like this: ... inputs: [ 'onOutside' ] ... export class ClickOutsideDirective { @Output() onOutside: EventEmitter ...

Using Phonegap alongside ons-scroller and ons-button

Recently, I have been using Phonegap with the Onsen UI system on iOS devices. I encountered an issue where buttons included within an ons-scroller were not clickable when running on an iPad or iPhone. Here is the code snippet that caused the problem: < ...

"Exploring the Power of ZF2 with Restful APIs and Image

I am currently in the process of developing a website utilizing Zend Framework 2 in combination with AngularJS. The backend consists of a restful webservice running on ZF2, while AngularJS is used on the client side to interact with this webservice. My ne ...

Extract the JSON information to find the <highlighting> tag used to emphasize text within a specific field

{ "responseHeader": { "status": 0, "QTime": 32 }, "response": { "numFound": 21, "start": 0, "docs": [ { "description": "A unique wave design sets apart this wedding band, craft ...

Tips for determining the size and identifier of a newly appended element in jQuery?

Struggling to create a select element with a width="347px" and id="select-box-1". I attempted to use .append("select"), but my search on .append() didn't yield the desired results. Unsuccessful Attempt: .append("< ...

Retrieving a JSON object that has been exported using Mongoose in Node.js

Recently diving into the world of Node.JS, I encountered a perplexing issue that has me stumped. In my upcoming_events.js file, I have an events object that I am exporting in the following manner: module.exports = function(passport, FacebookStrategy, con ...

The child_process module has yet to be loaded

Exploring NodeJS to execute a PowerShell script from JavaScript. Found this code snippet online: var spawn = require("child_process").spawn, child; child = spawn("powershell.exe",["c:\\test\\mypstest.ps1 -arg1 1"]); child.stdout.on(" ...

Sharing configurations between a Node.js application and client-side JavaScript

I am facing an issue where I need to use a config object in both my node app and browser. Below is the path and content of the configuration file: path: [app]/public/js/config.js content: var config = { "foo": "bar", "num": 42, "list": ["a" ...