Home › Forums › JavaScript › Parent menu trigger button
- This topic is empty.
-
AuthorPosts
-
October 19, 2018 at 3:01 am #277856vulkanusParticipant
Hi everyone,
Anyone can help me to develop a little code to prevent trigger button in mobile?
I have a menu accordion it open with js, so, when we press the button to open submenu for the first time, it opens, then if it clicks again it will trigger the url
I want to avoid that, only fire the URL when we quick double click.
Here an example: https://codepen.io/Vulkanus/pen/YJYvQY
Do this:
1 – press “submenu” text
2 – press “submenu2” text
3 – Then press “submenu” text again.Thank you
October 19, 2018 at 5:33 am #277860chris_2080ParticipantHi,
You can try this:
$("ul#primary-menu > li.menu-item-has-children").on("click", function(e) { return false; }).dblclick(function(e) { var win = window.open($(this).children().attr('href'), '_blank'); win.focus(); return false; });
October 19, 2018 at 7:23 am #277861vulkanusParticipantOctober 22, 2018 at 1:17 am #277941vulkanusParticipantHi @chris_2080
Good day,
Can I ask you something else?
I need the href of the submenu, trigger only the first click, not as it is in the parent.Parent href == 2 clicks
Child (submenu) href == clickThank you once more.
cumpsOctober 22, 2018 at 2:21 am #277942chris_2080ParticipantHi @vulkanus
If I understood you correctly:
$(".sub-menu > .menu-item").one("click", function(e) { e.preventDefault(); alert($(this).children().attr('href')); return false; });
October 22, 2018 at 2:32 am #277943vulkanusParticipantThank you
with the excerpt of your code, I adapted, this line, is what I want
window.open($(this).children().attr('href'), '_self');
basically the parent has to trigger the second click, the child to the first
With the full code, can be optimized?
$(“ul#primary-menu > li.menu-item-has-children”).one(“click”, function(e) {
e.preventDefault();
return false;
});$(“ul#primary-menu > li.menu-item-has-children”).on(“click”, function(e) {
return false;
}).dblclick(function(e) {window.open($(this).children().attr('href'), '_self'); return false; }) $(".sub-menu > .menu-item").one("click", function(e) { window.open($(this).children().attr('href'), '_self'); return false;
});
October 22, 2018 at 4:43 am #277944chris_2080Participantyou can combine it:
$('ul#primary-menu > li.menu-item-has-children').one('click', function(e) { e.preventDefault(); return false; }).on('click', function(e) { return false; }).dblclick(function(e) { window.open($(this).children().attr('href'), '_self'); return false; });
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.