Chrome is experiencing a delay in closing the Select Option dropdown menu

On my webpage, I have two select option buttons placed on different tabs. Whenever one button is changed, I want to update the value of the other button and assign it to a specific element like a span in the example code provided. While everything works smoothly, there seems to be a slight delay in closing the dropdown menu when changing the value. Surprisingly, this issue only occurs in certain browsers like Firefox.

View jsfiddle

Here's my HTML Code:

<select class="select one" >
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
</select><br><br><br>
<select class="select two">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
</select>
<br><br><br>
 <span class="value"></span>

JQuery

var lang =  $('select.one').val();
$('span.value').text(lang);

$('select.select').change(function(){
            lang = $(this).val();
            $('span.value').text(lang);
            if ($(this).hasClass('one')) {
                    $('.two').val($(this).val()).trigger('change'); 
            }
            else{
                $('.one').val($(this).val()).trigger('change'); 
                }

        });

Thanks a lot in advance for your help!

Answer №1

view the fixed demo on our website

The issue is arising because of multiple changes happening simultaneously. To fix this, simplify your code to the following:

var language = $('select.one').val();
$('span.value').text(language);

$('select.select').change(function () {
  language = this.value;
  $('span.value').text(language);
  $('.select').val(language);
});

Answer №2

Here is an alternative solution for you to consider:

let selectedLanguage = $('.select.one').val();
$('.value').text(selectedLanguage);

$('.select').change(function (e) {
    $('.select').val(this.value);
    $('.value').text(this.value);
});

The issue arose from the use of the .trigger() method, which caused unnecessary lookups and repetitive value setting in the DOM elements.

Take a look at the updated fiddle here.

Answer №3

My day was consumed by a frustrating issue with a simple HTML selection option in react. It felt like there was a 1 second lag for every action I tried to take on the select element. After updating Chrome, the problem magically disappeared, yet it never occurred when using Firefox.

I have a theory that Chrome automatically updates itself but doesn't properly apply the changes until the browser is restarted, causing bizarre glitches like the one I experienced with the select operation. While this isn't the first time I've encountered odd behavior in Chrome, it's certainly not a common occurrence.

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

Determining if a specific time falls within a certain range in JavaScript

I'm currently working on a Node.js application, but I have limited experience with Javascript. As part of my application, I need to implement validations for events and ensure that no two events can run simultaneously. To achieve this, I have set up ...

Display options in Material-UI autocomplete only upon clicking the icon

Is there a way to display the options list only when clicking on the arrow icon as opposed to the textfield itself? I have reviewed the documentations without success in finding a solution. Example ...

Animating a Canvas to Follow Mouse Coordinates

I am looking for a way to animate a circle moving towards specific coordinates, similar to the game . I have attempted using the jquery animate() function, but it is too slow due to the constant updating of the target coordinates. Is there a faster metho ...

Is it required to double click checkboxes to uncheck them?

My checkboxes require 2 clicks to be unchecked, even though one click is enough to check them. This issue occurs in all 7 checkboxes and there is no onchange() function or similar in TS. import { Component, OnInit, Inject } from '@angular/core&apos ...

Having trouble locating a method in $scope following angular $compile

Apologies for the simple question, I am a beginner in AngularJS and front-end development. I am attempting to create a modal using bootbox as shown below: In Service: function _modalData(){ let element = "<div onclick=\"saveSelecti ...

insert a gap between two elements in the identical line

Is there a way to create spacing between two text fields in the same row? I have tried using margins, paddings, and display flex in the css file but haven't been successful. import "./styles.css"; import TextField from "@material-ui/cor ...

Flashing images with jQuery Flickrush - Encasing the image within <li> tags

I have a div with an unordered list inside: <div id="flickr"> <ul></ul> </div> Currently, I am utilizing a plugin found at this link. To make it functional, I've included the following Javascript code: $(function() { $( ...

A straightforward jQuery conditional statement for dynamically generated content

If the div '#ajax' contains content, I want to make the div '.container' clickable. Here is the basic jQuery script I have implemented: if ('#ajax:empty') { $('.container').css('pointer-events', ' ...

How can I deactivate the main color of the FormLabel when the focus is on the radio button group?

Is there a way to change the color of FormLabel to black instead of the primary color when the radio button group is focused? const styles = { formLabel: { color: "#000" }, formLabelFocused: { color: "#000" } }; function App({ classes } ...

Tips for troubleshooting a sass file that is not displaying changes in the browser

Currently working on my portfolio website using bootstrap and sass along with a theme kit. Initially, I attempted to implement a grid column style for the intro-section but had a change of heart and deleted the style. Surprisingly, every time I refresh my ...

What are the distinctions between loading my index HTML file and utilizing an HTTP server?

As I continue to enhance my coding skills, I have experimented with npm, webpack, and http-server. Typically, I utilize http-server to view the changes made through React on the index.html file by opening it on localhost. However, I recently discovered t ...

JSON: Automatically choose the radio button based on the provided response

Is there a way to automatically select the checked state of radio buttons based on data retrieved from a database? I need to populate this form's radio button with data <div class="col-md-4"> <label> <input type="radio" name="m ...

Codeceptjs does not have the capability to scroll or swipe down without being linked to a specific element

I'm facing an issue with scrolling/swiping down in an Android application while using codeceptjs. The method I'm currently using only works on the visible element, but I need to scroll down to the bottom of the page or a specific element without ...

Handling Pop-up Windows in Puppeteer using NodeJS

During my training exercises, I encountered a situation where I needed to click on a button that opens an internal "pop-up" from a specific page on Amazon. Unfortunately, Puppeteer was unable to detect this pop-up, making it difficult for me to interact wi ...

What is the best method for resetting the CSS style of a specific DOM subtree?

While working on a Chrome Extension, I encountered a problem where an HTML subtree and CSS style sheet injected into the original page were being affected by the original CSS. Despite my attempts to override the styles, it seemed unfeasible to manually set ...

Challenges with Internal Styling on Wordpress Sites

Okay. I've been dealing with some internal style issues on my Wordpress website. After dedicating hours to trying to change styles for various elements, I realized that the main html file contained a bunch of internal style sheets that were overridin ...

AngularJS integration with Bootstrap Confirmation jQuery plugin

I am currently struggling to implement the Bootstrap-Confirmation plugin with AngularJS. Despite following instructions from this YouTube tutorial, I cannot seem to get the directive to function correctly. A related query on Stack Overflow references a di ...

What factors contribute to a one-hour discrepancy between two time stamps, deviating from the anticipated value?

Let's consider the dates '2022-04-01' and '2022-05-15'. When I calculated their deviation using Chrome devtools, here are the results: https://i.stack.imgur.com/tSZvk.png The calculated result is 3801600000. However, when my frie ...

Opening a new window in JavaScript and passing additional parameters

I am facing an issue with my JavaScript link There is a hidden input field named "domain" Below is a div with an onclick script: <div id="button" onclick="window.open('http://www.mylink.nl/?domein=' + document.getElementById('domein&ap ...

Using Javascript with the Google Calendar API: How can I swiftly make a new event with the Quick Add feature?

Currently, I am exploring the Google Calendar API and struggling with implementing a Quick Add Event using javascript. Is it possible to achieve this task? Are there any resources or examples that can help me understand how to do it? My issue lies in the ...