Home  >  Q&A  >  body text

Shows a submenu when the mouse is hovered over the button

<p>I'm looking for a solution where when I hover over a button a submenu pops up. Currently the menu is only shown when clicked. Does anyone know what I need to change so that when hovering over a button the menu shows up and when clicked the menu stays there. </p> <p>Solution: Change hover to mouseover. </p> <p><strong>Does anyone know how to make all sections (sect1...) not show on mouseover? </strong></p> <pre class="brush:php;toolbar:false;"><script> var divs var btn1 = document.getElementById("btn1"); var btn2 = document.getElementById("btn2"); var btn3 = document.getElementById("btn3"); btn1.mouseover = function(event){ event.preventDefault(); toggleDivs("sect1"); }; btn2.mouseover = function(event){ event.preventDefault(); toggleDivs("sect2"); }; btn3.mouseover = function(event){ event.preventDefault(); toggleDivs("sect3"); }; function toggleDivs(s){ //reset document.getElementById("sect1").classList.remove("shown"); document.getElementById("sect2").classList.remove("shown"); document.getElementById("sect3").classList.remove("shown"); //show document.getElementById(s).classList.add("shown"); } //force button1 state initialise, if required //btn1.focus(); //btn1.click(); </script> <style> .elementor-editor-active .hidden{ display:block; } .hidden{ display:none; } .show{ display: block !important; } </style></pre></p>
P粉021708275P粉021708275437 days ago628

reply all(1)I'll reply

  • P粉883223328

    P粉8832233282023-09-01 09:27:39

    There is no "hover" event. You have to use mouseover, mouseenter and mouseout to handle it.

    https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event

    reply
    0
  • Cancelreply