Display and conceal a div using jQuery upon hovering, and maintain its visibility until the mouse moves out

I am having an issue with my language drop down menu.

When I hover over the flag, the language options should display and stay visible. However, when I move the mouse away from the language options or hover over the flag again, the language options should be hidden. Currently, it is showing and hiding instantly.

Here is the HTML code:

<a href="" class="lang"><img src="images/english.jpg" alt="en" id="langflag"></a>
        <div class="select-lang" style="display:none;">
              <h2>In Your Language</h2>
               <ul>
               <li><a href=""><img src="images/in_14.png" alt="in"> हिन्दी   </a></li>
               <li><a href=""><img src="images/es_14.png" alt="es"> Español</a></li>
               <li><a href=""><img src="images/fr_14.png" alt="fr"> Français</a></li>
               <li><a href=""><img src="images/de_14.png" alt="de"> Deutsch</a></li>
               <li><a href=""><img src="images/ro_14.png" alt="ro"> Română</a></li>
               <li><a href=""><img src="images/br_14.png" alt="br"> Brasil...

And here is the jQuery script:

$(document).ready(function() {
$( "#langflag" ).hover(function() {
   $( ".select-lang" ).slideToggle( 400, function() {
       // Animation complete.
    });
});
});

Check out the Fiddle here.

Answer №1

$( "#langflag" ).on('mouseenter', function() { 
   $( ".select-lang" ).slideToggle( 400, function() {
       // Animation finished.
    });
});

// Keep the language selection open when mouse is over #langflag, hide it if the mouse leaves both
$( ".select-lang, #langflag" ).on('mouseleave', function() {
   if ($(this).attr('id') != 'langflag') {
      $( ".select-lang" ).slideToggle( 400, function() {
         // Animation done.
      });
   }
});

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

Is it false to say that false in Javascript is still false?

After conducting some research, it appears that the question I have in mind has not been asked before, or maybe it has slipped under my radar. A rational approach would be to consider the following logic: false && false === true false && true === false t ...

Issue with Angular controller failing to load when link is clicked

I am currently developing a webpage that incorporates Angular and responds to ajax requests by populating data into a table. When I manually enter the address, everything works as expected. However, if I navigate to the page using a link ( <a href="/pro ...

Generate a Table Using JSON Data with AngularJS and ng-repeat

I have some JSON data that looks like this: { "Workout1": { "Name": "First", "Rounds": [ { "Exercises": [ { "Name": "Exercise1", "Repeat": 10 }, { "Name": "Exercise2 ...

Is it possible to disable the next and previous buttons in jCarousel?

I am currently using the jCarousel slider from for my website. The slider displays one image at a time, with a total of four images. I want to hide the previous arrow when displaying the first image and hide the next arrow when displaying the fourth image ...

three.js: PerspectiveCamera: turn off zoom ability

Is there a way to prevent zooming with the mousewheel? I have checked the camera API here: Despite my efforts, I couldn't find a solution through Google searches. It seems like the only option may be to examine the source code. Any suggestions or i ...

Exclude certain APIs from utilizing basic authentication in Fastify

I currently have two APIs set up: /auth and /no-auth. My goal is to only use basic authentication for one of them. To implement this, I am using the fastify-basic-auth plugin with fastify in a node environment. The /auth route should require authenticat ...

Incorporate Dynamic Motion into jQuery Content Panels

Currently, I am using a jQuery Content Tab which is functioning well but lacks any animation. My goal is to incorporate animation effects such as fading or scrolling in when the tab is clicked, and the next content is displayed. If there are any other crea ...

Guide on integrating reCaptcha v2 with vue 3

Struggling with adding reCaptcha to my Vue 3 project, I've attempted various methods without success. If anyone has successfully integrated reCaptcha into a Vue 3 project, your help would be greatly appreciated. I attempted to use the vue-reCaptcha n ...

Is it possible to combine Bootstrap 2.3.1 with newer versions such as 4.0 or 3.x.x?

My current website is built using Bootstrap 2.3.1, but now I am looking to update to a new version of Bootstrap. However, when I tried updating, the entire UI changed drastically and the website started to look clumsy. Instead of completely replacing the ...

Failed Ajax request is caused by an incorrect URL

In my current project using Ajax, I encountered a peculiar issue. The main page, Main.html, is accessible locally at 'http://localhost/Main.html', and it is styled with Bootstrap. Upon loading the page, jQuery verifies the existence of a particu ...

Tips for seamlessly integrating a Shopify App into a personalized HTML Call to Action

I'm in the process of putting together a Shopify online store and I've been able to put together a customized popup using HTML, CSS, and JS. I've also incorporated an app in Shopify for email marketing purposes. However, I'm looking to ...

Is there an equivalent to Android's addJavascriptInterface() for desktop webkit browsers?

In my quest to explore Android UI capabilities, I stumbled upon the addJavascriptInterface() method documentation that enables the exposure of methods on an Android Java object to Javascript within a WebView component. The concept of bridging the gap betw ...

What is the best way to adjust the value within a span element using plus and minus buttons located near an input field?

Is there a way to implement input addition using + and - buttons, even though it has been working without buttons so far? How can I achieve this functionality with the help of javascript or jquery? // To calculate the sum of three input values in a spa ...

It is not possible to submit a hidden input when its value is changed

Has anyone encountered the same issue as mentioned in this question? I've searched for a solution, but unfortunately, I haven't been able to find one! I tried going through this answer, but it didn't work for me either! Would greatly appr ...

What methods can be used to modify element attributes in Python?

I'm curious about how to utilize Python to modify an element in the HTML code of a webpage: In this case, I need to change it from: <input _ngcontent-mcp-c552="" type="number" name="bpm" placeholder="0" min= ...

Why is it that the .forEach() function has the ability to alter the Vuex state?

After extracting two sets of balances from my vuex state, I decided to merge them into a new array of entries. However, an error is thrown when I try to loop through my copies of the vuex state. Am I missing something? It seems that the issue lies in the ...

Utilizing Firebase 9.0.1 Functions in Vue.js 3

As a newcomer to Vue, I decided to tackle my second tutorial which involved integrating Firebase backend with Vue. However, the tutorial was based on Vue 2 and an older version of Firebase. Determined to stay current, I set out to replicate the project usi ...

Struggling with jquery .append issue

Here is the HTML code snippet: <div class="expand"> <div class="title" id="SectionTitle2">Academics</div> <input type="button" onclick="showTitleForm('2');" name="editTitle2" value="Edit Title"> <form id="titleForm2" m ...

When you hover over it, the text moves above the background content

I am looking to enhance my table by having the text expand and hover over the content with a white background. I have achieved the expand effect, but I am struggling to get the overflow to work properly. You can view the code in action on JsFiddle: JsFiddl ...

Exploring td data inside tr element using LXML

Is there a better way to parse individual statistics from the Yahoo Finance tables for formatting purposes? The current method involves repeating code to retrieve stats within each row of the table, as shown in the example below. It seems inefficient - a ...