I have a ASP.NET custom server control menu with the following jQuery in the head of the master page. The problem is that when I have a button on a regular form it causes the slide action in the side menu in the master page to activate every time it is clicked in the form… how can I prevent this so that the slide action only happens on initial page load or when a different men item is clicked?
$(document).ready(function() {
// Expand/Collapse All
$('#example1 .expand_all').click(function() {
$('#menu1 > li > a.collapsed').addClass('expanded').removeClass('collapsed').parent().find('> ul').slideDown('medium');
});
$('#example1 .collapse_all').click(function() {
$('#menu1 > li > a.expanded').addClass('collapsed').removeClass('expanded').parent().find('> ul').slideUp('medium');
});
// Slide
$("#menu1 > li > a.expanded + ul").slideToggle("medium");
$("#menu1 > li > a").click(function() {
$(this).toggleClass("expanded").toggleClass("collapsed").parent().find('> ul').slideToggle("medium");
});
});
Have you tried using
.one()? Maybe this will help: .one()Edit:
I’m not sure if this is the best way to solve this: