Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

402
Vistas
Make title disappear when button is clicked

How can I make the text disappear when the menu button is clicked but then come back when you exit the menu?

My efforts

$("#menuBtn").click(function() {
  if ($("ul").css("display") == "none") {
    $("ul").fadeIn();
  } else {
    $("ul").fadeOut();
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" id="menuBtn">Click</button>

<ul>
  <li>Menu</li>
</ul>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your code works and do what you want, you are just missing parenthesis and curly brackets. Try copying this code:

$("#menuBtn").click(function() {
  if($("ul").css("display") === "none") {
    $("ul").fadeIn();
  } 
  else {
    $("ul").fadeOut();
  }
})

//Fade out when the mouse leaves the menu
$("ul").mouseleave(function() {
  $("ul").fadeOut();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="menuBtn">Menu button</button>
<ul style="display: none">
  <li>Menu item 1</li>
  <li>Menu item 2</li>
  <li>Menu item 3</li>
</ul>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can set one extra class (hidden) to html element that you want to hide in order to detect if it is hidden or not. Then you can use fadeIn() and fadeOut () base on html element state.

$(document).ready(function(){
  $(".btn1").click(function(){
    if ($("ul").hasClass("hidden")) {
        $("ul").removeClass("hidden").fadeIn();
    }
    else {
        $("ul").addClass("hidden").fadeOut();   
    }
  });
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda