Good evening guys, I do the dropdown menu and I want to implement it on tablets and mobile phones so that with the first click it unfolds and with the second click on the link of this menu, something like

if($("#element).click(function() { $("#element").dropdown(); if("#element").click(function() { location.href = $(this).attr('href');});}); 

Tell me if this is possible at all, or am I thinking in the wrong direction?

  • Well, if you have already opened it, you can simply delete the handler and leave a bare link, or hang up the class when you click on the href - Redr01d transition

2 answers 2

If it doesn't matter to use Jquery, you can use addEventListener and hang an event handler on any menu item you need.

https://developer.mozilla.org/ru/docs/Web/API/EventTarget/addEventListener

  • Thank you, but I did not find a solution in my time I had to abandon js and add another button just for the drop-out event, but your method is good, I will definitely test it in the future. - Constantine Shibaev
  • You are welcome! There is a similar question: stackoverflow.com/questions/8996015/… Just for Jquery. Recommend methods .on () or .delegate () - Anton Kovylin
 $("#element").click(function() { if ($(this).hasClass("clicked")) { location.href = $(this).attr('href'); } else { $(this).addClass("clicked"); $(this).dropdown(); } return false; }); 
  • and if someone clicks to another place, ts-ts-ts is not thought out, a counter is needed here and discharged - Vasily Barbashev
  • How do I know what will happen if someone clicks to another place? Can the tablet explode in the hands of the user? - Igor
  • Well, you suggested the simplest option, which is logically incorrect. Yes, it performs the function, but it does not work correctly) - Vasily Barbashev