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

Enabling communication between App.js and a separate class in React

How can I integrate React Scheduler with JSON data in my app and pass shifts and functions from App.js to DataSheet.js for updating the data? Is there a more efficient way to enable database updates directly from DataSheet? App.js: import React from &apos ...

Facing a selection list issue on a web application built with Flask and Vue.js

I'm trying to integrate Flask and Vue.js together, but I've encountered an issue with my select element. The following code snippet is present in my HTML file: <div class="col-sm-10"> <select class="form-select" v-mod ...

Determining if a user is already logged in from a different device using express-session

After a user logs in, I assign the username to their session with the code: req.session.username = "...."; This identifies the session with a username, but now I need to figure out how to detect if this same username is already logged in from another dev ...

What is the best way to verify the presence of a file using jQuery?

I am using "tinyMCE" dynamically on a single page. To modify the content in "tinyMCE", I have to use the "setContent" function. However, I am unsure how to check for the existence of a file (using PHP's is_file function) either within ajax or before ...

The Ajax script is failing to retrieve search results

I am encountering an issue with my normal AJAX search functionality in which I need to retrieve data from a database when the form is submitted. The problem arises when trying to filter data between two specific dates using separate pages, it works fine bu ...

Tips for making an image fill the entire screen with a header using React Navigation

My screen includes an image and I would like to capture the full-size screen with the header displayed. However, using position: "absolute" does not properly wrap the header, and setting header: null is not an option since I still want the back button to b ...

Fixing Typescript assignment error: "Error parsing module"

Trying to assign an object to the variable initialState, where the type of selectedActivity is Activity | undefined. After using the Nullish Coalescing operator (??), the type of emptyActivity becomes Activity. However, upon execution of this line, an err ...

Is there a way to create animated CSS box-shadow depth using jQuery or CSS3 transitions?

This code snippet applies delays but doesn't seem to update the style changes until the loop completes: for (i=20;i>=0;i--) { var boxShadow = i+"px "+i+"px "+i+"px #888"; $('article').css("box-shadow", boxShadow); ...

The function parameter in Angular's ngModelChange behaves differently than $event

How can I pass a different parameter to the $event in the function? <div class='col-sm'> <label class="col-3 col-form-label">Origen</label> <div class="col-4"> <select ...

Error displaying Font Awesome icons

I am currently facing challenges with managing my assets using webpack. I have installed font-awesome via yarn and imported the .css files into my webpage. However, despite my HTML recognizing the classes from font-awesome.css, the icons I am attempting to ...

What is the best way to position HTML labels with CSS3 flexbox?

Check out my codepen to see what I need by clicking on this link: https://codepen.io/tbellmer/pen/RdxBdQ I am new to this and although the form works, I require help with the design. I want both the Action: and Comment: labels to be aligned to the right. ...

SweetAlert2 not displaying properly in Ionic6 - troubleshooting the issue

My current project is an Ionic 5 Angular project with SweetAlerts2 popups. Recently, I decided to upgrade to Ionic6 and encountered an issue where the SweetAlerts2 popups are not displaying correctly. The alert seems to only show up in the header, leaving ...

Creating a Dual Y-Axis Chart with Two Sets of Data in chart.js

I utilized the chart.js library to write the following code snippet that generated the output shown below. My primary concern is how to effectively manage the labels on the horizontal axis in this scenario. CODE <!DOCTYPE html> <html lang="en"& ...

Getting your JS project off the ground with NPM!

I am looking to develop a vanilla JavaScript project that utilizes npm packages, but I want to do it without using bundlers like Webpack. Here is a basic structure: index.html: <div id="app"></div> <script src="./index.js" type="module"&g ...

AngularJS tips for resolving an issue when trying to add duplicates of a string to an array

Currently dealing with a bug that occurs when attempting to push the same string into an array that has already been added. The app becomes stuck and prevents the addition of another string. How can I prevent the repeat from causing the app to get stuck w ...

Are you looking for a way to prevent the default behavior of an event in angular-ui-router 1.0.x? Check out

Recently, I made a change in my code where I replaced $stateChangeStart with $transitions.onStart $rootScope.$on('$stateChangeStart', function(e, ...){ e.preventDefault(); // other code goes here... }); Now, the updated code looks lik ...

Error in Jquery Ajax due to an unexpected token ':' being caught

My spring MVC application is experiencing an issue when using jQuery AJAX to send data to the server from my HTML page. The error message indicates a problem with dataType: 'json', specifically pointing out the unexpected symbol :. $(document).r ...

The Ajax dropdown is failing to display any results

I created a script to filter through a database and retrieve all the records that contain a specific value. I have set up an AJAX dropdown for selecting the value, but when I make a selection in the dropdown, it does not show any results. Any assistance on ...

Ways to restrict the quantity of Firebase compound indexes required for querying with various filters

I'm in the process of developing a Firestore project that includes group chats and forums where users can filter posts based on various criteria: Number of likes Presence of attachments (photos and/or files) 4 Tags (Questions, Exams, Assignments, Not ...

Parallel with one <div> and subsequently another <div>

I have been challenged by HTML and CSS to embrace humility: Attempting to replicate the following design: Here is my effort: <div> <div style="width:800px;"> <div style="float:left;width:25%;background-color:red;">Facility #: COM ...