jQuery allows you to hide a div when the mouse leaves it

HTML

<div class="container">
    <div class="section" id="block1">Section-1</div>
    <div class="section" id="block2">Section-2</div>
    <div class="section" id="block3">Section-3</div>
    <div class="section" id="block4">Section-4</div>

    <a href="javascript:void(0);" class="btn01">Click1</a>
    <a href="javascript:void(0);" class="btn02">Click2</a>
    <a href="javascript:void(0);" class="btn03">Click3</a>
    <a href="javascript:void(0);" class="btn04">Click4</a>    
</div>

CSS

.container {
    position:relative;
}
.section {
    width:500px;
    height:300px;
    background-color:#f00;
    position:absolute;
    top:50px;
    display:none;    
}

JQUERY

$('.container').children('a').on('click',function(){
  $('.container').children('div').hide().eq($(this).index()-4).fadeIn(400);
});

JSfiddle

When clicking on any link within the container div, the related section is displayed. However, I am unable to hide the section when the cursor moves away from it. How can this be achieved?

Answer №1

Check out this solution

$('.menu').on('mouseout',function(){
$(this).hide();
});

View the demo here

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

Tips for updating the contents of a div dynamically in JavaScript/jQuery without the need for clicking a button or a link

Is there a way to automatically reload or refresh the content of a specific div element without refreshing the entire page, and without any user interaction such as clicking a button or link? I am looking to update the div with the id 'div_graph' ...

What is the best way to get rid of a tooltip from a disabled button

I am facing an issue with my button that is disabled using ng-disabled. The problem is that the button still shows a tooltip even when it is disabled. I need to find a way to remove the tooltip when the button is disabled. Check out my Button ...

The Bootstrap logo and the navbar are displayed on separate lines

I'm having trouble creating the navigation bar that I envision. I want the logo to be positioned on the top left, with the navigation bar centered on a new line below it. When the bar collapses, I want the button to align to the right of the logo on t ...

Is there a way to change the input type=file value?

What is the best method for customizing a file upload using input type="file" in HTML? Here is an example of what I am trying to achieve: <form enctype="multipart/form-data" action="xmlupload" method="post" name="form1" id="form1"> <input type ...

Troubleshooting an Angular.js "Hello World" application that is malfunctioning

I've been trying to get a simple Hello World app working by following different tutorials, but it doesn't seem to be functioning correctly. I've double-checked my code and everything looks right to me. Could someone please assist me in troub ...

Simplified JavaScript code for generating concealed input forms

Seeking assistance to enhance the form I designed, despite my limited knowledge in JavaScript programming. The objective is to develop a hotel search engine with the ability to specify the total number of rooms. Based on the selected number of rooms, addi ...

Having difficulty getting mask-image to function properly in Safari browser

My table row is styled with the following CSS code: .table-row-mask { mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); } <table><tr class="table-row-mask"><td>Test</td></tr></table> This ...

Utilizing jQuery to send multiple values via an ajax request

I am looking to modify this script to send multiple values using AJAX instead of just a single value. files.php $(".search_button").click(function() { var search_word = $("#search_box").val(); var dataString = 'search_word='+ search_word ...

Having trouble accessing DOM elements in Durandal

Running on Durandal, this mobile app features names and images on an HTML page. The function below helps format the page: define(function (){ function getAutors(myUrl) { $.ajax({ type: "GET", url: myUrl, data: { num ...

Error 500 occurred when attempting to access an external PHP file

I am currently utilizing WP Web Scraper version 3.2. When I place the shortcode or template tag (php code) directly into my page, the plugin functions correctly and displays the values. However, when I attempt to include the template tag in an external php ...

Implement modals using a for loop in Vue

I am facing an issue while trying to create modals for cards within loops. I attempted using v-bind:id="masa._id" and v-bind:data-target="'#'+masa._id", but the modal is not working. Can someone guide me on how to implement modals in loops? Belo ...

What is the most effective method for incorporating a floating section next to a Susy gallery?

Check out my latest progress on the codepen here The number of items displayed in the gallery is dynamic based on search results. However, I am looking to add a fixed area to the right side that remains visible as the user scrolls through the gallery. Ess ...

The HTML5/JQuery/JSON webpage is currently experiencing difficulties retrieving data

I'm having trouble with the code below. It's not displaying anything. Can anyone help me fix it? <!DOCTYPE html> <html> <head> <title>Flight Data</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/ ...

Angular not executing Jquery script in included HTML files

Underneath is a simple jquery code snippet: $(document).ready(function() { $("h2").click(function(){ alert("Hello world"); }) }); After clicking on any h2 tag in the website, an alert message will display. The code functions properl ...

Tips for utilizing an npm package in conjunction with Hugo

I created a basic hugo site with the following command: hugo new site quickstart Within the layouts/_default/baseof.html file, I have included a JavaScript file named script.js. Inside script.js, the code looks like this: import $ from 'jquery' ...

The app is having trouble loading in Node because it is unable to recognize jQuery

I am currently using Node to debug a JavaScript file that includes some JQuery. However, when I load the files, the $ sign is not recognized. I have installed JQuery locally using the command npm install jquery -save-dev. The result of "npm jquery -versio ...

Two child DIVs within a single parent DIV

I am struggling to keep two divs side-by-side within a parent div. Initially, I was able to position the image in the right div successfully, but when resizing the elements, everything became disorganized and I can't seem to fix it. As a beginner, I w ...

What is the method for moving the cursor to the MathQuill (0.10) field in order to immediately begin typing and making edits?

I am currently working on a plugin for Etherpad that allows for editing formulae using MathQuill. One issue I am facing is that when the toolbar is opened, I want the cursor to automatically move into the edit field. The field is mathquillified in the foll ...

Exploring the Power of Google Charts through Dynamic Data Retrieval with

I am new to posting on here, so please let me know if I am missing anything. Lately, I have been experimenting with AJAX and trying to create a basic dashboard that fetches data from our database and displays it on a web page using Google's table vie ...

creating tabulations and charts across various while loops

My goal is to create Tabs using information from the first while loop, and then populate a table within each Tab using data from the second while loop. The data is fetched date-wise from my 'treatment' table to generate the Tabs. The line items ...