Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
How to hide and show secondary header based on hover icon in primary header

i am trying to make two headers, the secondary header that has navigation is hidden. there is icon in the primary header. when i hover that icon the secondary header is shown, but when i remove the cursor from that icon the secondary header is also hides.

I want that the when i hover the icon the secondary header must be shown and not hide unless i remove the cursor from that secondary header.

what I have tried so far.

css

.active{
  display: block;
}
#menu_header{
  position: absolute;
  width: 100% !important;
  top: 0;
  background: red;
  display: none;
}

JQuery

jQuery(document).ready(function( $ ){
  $('#menu_header').hover(function(){
    $(this).addClass('active');
  }, function(){
    $(this).removeClass('active');
  })

  
  $('#hover_button').mouseenter(function() {
    $('#menu_header').show();
  }).mouseleave(function() {      
    if(!$('#menu_header').hasClass('active')){
      $('#menu_header').hide();
    }
  });
});

Please help me. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In the solution I developed, when the mouse hovers over the <h1> element, the <h2> element is displayed. To hide the <h2> element, the mouse must hover over the <h2> element and the mouseleave event must occur on the <h2> element. Alternative solutions that can be used:

  • The <h2> element is displayed when the cursor is over the <h1> element. Hiding the <h2> element requires a timeout and/or a mouseleave event on the <h2> element.
  • Only the <h1> element mouseenter and mouseleave events can be used to hide and show the <h2> element.

jQuery(document).ready(function( $ ){
  /* Edited the following line of code. */
  $('#menu_header').hover(function(){
    $('#menu_header').addClass('active');
  });
  
  /* Added the following line of code. */
  $('#menu_header').mouseleave(function(){
    $('#menu_header').addClass('passive');
    $('#menu_header').hide();
  });

  $('#hover_button').mouseenter(function() {
    $('#menu_header').show();
  });
});
.active{
  display: block;
}

#menu_header{
  position: absolute;
  width: 100% !important;
  top: 0;
  background: red;
  display: none;
}
<!DOCTYPE html>
<html lang="en">
  <head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <link rel="stylesheet" href="style.css">
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   <script src="main.js"></script>
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
   <title>Print-Shop Contact</title>
 </head>
 <body>           
    <h1><i id="hover_button" class="fa fa-camera-retro fa-2x"></i></h1>
    <h2 style="margin-top: 100px;" id="menu_header">TEST</h1>
 </body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!