Anchor only firing event when just a #
up vote
-2
down vote
favorite
I am struggling to find out why my click event is not firing. I have a menu which is overlayed over the main content. When the anchor is clicked, it should close the overlay and scroll to the element.
I can see the scrolling work (the overlay is partially transparent), but the event is not firing to close the overlay.
If I click the Contact Us link (which is currently just a #), the event is fired and the overlay does close.
(function($) {
$('#mobile-menu-toggle').click(function() {
if ($(this).hasClass('toggle-open')) {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeOut();
$(this).toggleClass("toggle-open");
} else {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeIn();
$(this).toggleClass("toggle-open");
}
});
$(document).on('click', '.ToggleMenu', function(event) {
alert("Clicked");
$("button.menu-toggle").trigger('click');
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="mobile-menu-toggle" class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="menu-label bdn-gsk"></span>
<div class="burger-icon">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</button>
<nav id="mobile-menu" class="mobile-menu" style="display:none;">
<div class="site-branding">
<h1 class="site-title bdn-gsk"><a href="#" rel="home">Menu Heading</a></h1>
</div>
<div class="menu-inner-wrap">
<div class="menu-wrap serif">
<div class="menu-main-menu-container">
<ul id="primary-menu" class="menu">
<li class="ToggleMenu"><a href="#Home">Home</a></li>
<li class="ToggleMenu"><a href="#About">About</a></li>
<li class="ToggleMenu"><a href="#WhatsOn">What's On</a></li>
<li class="ToggleMenu"><a href="#OurWork">Our Work</a></li>
<li class="ToggleMenu"><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</nav>
This is in a Wordpress site.
Thank you
jquery
add a comment |
up vote
-2
down vote
favorite
I am struggling to find out why my click event is not firing. I have a menu which is overlayed over the main content. When the anchor is clicked, it should close the overlay and scroll to the element.
I can see the scrolling work (the overlay is partially transparent), but the event is not firing to close the overlay.
If I click the Contact Us link (which is currently just a #), the event is fired and the overlay does close.
(function($) {
$('#mobile-menu-toggle').click(function() {
if ($(this).hasClass('toggle-open')) {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeOut();
$(this).toggleClass("toggle-open");
} else {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeIn();
$(this).toggleClass("toggle-open");
}
});
$(document).on('click', '.ToggleMenu', function(event) {
alert("Clicked");
$("button.menu-toggle").trigger('click');
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="mobile-menu-toggle" class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="menu-label bdn-gsk"></span>
<div class="burger-icon">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</button>
<nav id="mobile-menu" class="mobile-menu" style="display:none;">
<div class="site-branding">
<h1 class="site-title bdn-gsk"><a href="#" rel="home">Menu Heading</a></h1>
</div>
<div class="menu-inner-wrap">
<div class="menu-wrap serif">
<div class="menu-main-menu-container">
<ul id="primary-menu" class="menu">
<li class="ToggleMenu"><a href="#Home">Home</a></li>
<li class="ToggleMenu"><a href="#About">About</a></li>
<li class="ToggleMenu"><a href="#WhatsOn">What's On</a></li>
<li class="ToggleMenu"><a href="#OurWork">Our Work</a></li>
<li class="ToggleMenu"><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</nav>
This is in a Wordpress site.
Thank you
jquery
1
what kind of link is#Home
?
– guradio
Nov 12 at 0:22
2
Consider using consistent indentation in your code - it'll make debugging much easier (not only for others, but for you as well)
– CertainPerformance
Nov 12 at 0:29
2
I moved your code into a snippet and, without any css, it seems like it may be working... care to verify that or add your styles, if there is anything covering the menu the click may not register...
– lucascaro
Nov 12 at 0:39
Thanks - I will check all css and see if I can find out why it is not working
– pbs
Nov 12 at 9:07
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I am struggling to find out why my click event is not firing. I have a menu which is overlayed over the main content. When the anchor is clicked, it should close the overlay and scroll to the element.
I can see the scrolling work (the overlay is partially transparent), but the event is not firing to close the overlay.
If I click the Contact Us link (which is currently just a #), the event is fired and the overlay does close.
(function($) {
$('#mobile-menu-toggle').click(function() {
if ($(this).hasClass('toggle-open')) {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeOut();
$(this).toggleClass("toggle-open");
} else {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeIn();
$(this).toggleClass("toggle-open");
}
});
$(document).on('click', '.ToggleMenu', function(event) {
alert("Clicked");
$("button.menu-toggle").trigger('click');
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="mobile-menu-toggle" class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="menu-label bdn-gsk"></span>
<div class="burger-icon">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</button>
<nav id="mobile-menu" class="mobile-menu" style="display:none;">
<div class="site-branding">
<h1 class="site-title bdn-gsk"><a href="#" rel="home">Menu Heading</a></h1>
</div>
<div class="menu-inner-wrap">
<div class="menu-wrap serif">
<div class="menu-main-menu-container">
<ul id="primary-menu" class="menu">
<li class="ToggleMenu"><a href="#Home">Home</a></li>
<li class="ToggleMenu"><a href="#About">About</a></li>
<li class="ToggleMenu"><a href="#WhatsOn">What's On</a></li>
<li class="ToggleMenu"><a href="#OurWork">Our Work</a></li>
<li class="ToggleMenu"><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</nav>
This is in a Wordpress site.
Thank you
jquery
I am struggling to find out why my click event is not firing. I have a menu which is overlayed over the main content. When the anchor is clicked, it should close the overlay and scroll to the element.
I can see the scrolling work (the overlay is partially transparent), but the event is not firing to close the overlay.
If I click the Contact Us link (which is currently just a #), the event is fired and the overlay does close.
(function($) {
$('#mobile-menu-toggle').click(function() {
if ($(this).hasClass('toggle-open')) {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeOut();
$(this).toggleClass("toggle-open");
} else {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeIn();
$(this).toggleClass("toggle-open");
}
});
$(document).on('click', '.ToggleMenu', function(event) {
alert("Clicked");
$("button.menu-toggle").trigger('click');
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="mobile-menu-toggle" class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="menu-label bdn-gsk"></span>
<div class="burger-icon">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</button>
<nav id="mobile-menu" class="mobile-menu" style="display:none;">
<div class="site-branding">
<h1 class="site-title bdn-gsk"><a href="#" rel="home">Menu Heading</a></h1>
</div>
<div class="menu-inner-wrap">
<div class="menu-wrap serif">
<div class="menu-main-menu-container">
<ul id="primary-menu" class="menu">
<li class="ToggleMenu"><a href="#Home">Home</a></li>
<li class="ToggleMenu"><a href="#About">About</a></li>
<li class="ToggleMenu"><a href="#WhatsOn">What's On</a></li>
<li class="ToggleMenu"><a href="#OurWork">Our Work</a></li>
<li class="ToggleMenu"><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</nav>
This is in a Wordpress site.
Thank you
(function($) {
$('#mobile-menu-toggle').click(function() {
if ($(this).hasClass('toggle-open')) {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeOut();
$(this).toggleClass("toggle-open");
} else {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeIn();
$(this).toggleClass("toggle-open");
}
});
$(document).on('click', '.ToggleMenu', function(event) {
alert("Clicked");
$("button.menu-toggle").trigger('click');
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="mobile-menu-toggle" class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="menu-label bdn-gsk"></span>
<div class="burger-icon">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</button>
<nav id="mobile-menu" class="mobile-menu" style="display:none;">
<div class="site-branding">
<h1 class="site-title bdn-gsk"><a href="#" rel="home">Menu Heading</a></h1>
</div>
<div class="menu-inner-wrap">
<div class="menu-wrap serif">
<div class="menu-main-menu-container">
<ul id="primary-menu" class="menu">
<li class="ToggleMenu"><a href="#Home">Home</a></li>
<li class="ToggleMenu"><a href="#About">About</a></li>
<li class="ToggleMenu"><a href="#WhatsOn">What's On</a></li>
<li class="ToggleMenu"><a href="#OurWork">Our Work</a></li>
<li class="ToggleMenu"><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</nav>
(function($) {
$('#mobile-menu-toggle').click(function() {
if ($(this).hasClass('toggle-open')) {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeOut();
$(this).toggleClass("toggle-open");
} else {
$("body").toggleClass("mobile-menu-open");
$("#mobile-menu").fadeIn();
$(this).toggleClass("toggle-open");
}
});
$(document).on('click', '.ToggleMenu', function(event) {
alert("Clicked");
$("button.menu-toggle").trigger('click');
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="mobile-menu-toggle" class="menu-toggle" aria-controls="primary-menu" aria-expanded="false">
<span class="menu-label bdn-gsk"></span>
<div class="burger-icon">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</button>
<nav id="mobile-menu" class="mobile-menu" style="display:none;">
<div class="site-branding">
<h1 class="site-title bdn-gsk"><a href="#" rel="home">Menu Heading</a></h1>
</div>
<div class="menu-inner-wrap">
<div class="menu-wrap serif">
<div class="menu-main-menu-container">
<ul id="primary-menu" class="menu">
<li class="ToggleMenu"><a href="#Home">Home</a></li>
<li class="ToggleMenu"><a href="#About">About</a></li>
<li class="ToggleMenu"><a href="#WhatsOn">What's On</a></li>
<li class="ToggleMenu"><a href="#OurWork">Our Work</a></li>
<li class="ToggleMenu"><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</nav>
jquery
jquery
edited Nov 12 at 0:38
lucascaro
3,38611530
3,38611530
asked Nov 12 at 0:16
pbs
139113
139113
1
what kind of link is#Home
?
– guradio
Nov 12 at 0:22
2
Consider using consistent indentation in your code - it'll make debugging much easier (not only for others, but for you as well)
– CertainPerformance
Nov 12 at 0:29
2
I moved your code into a snippet and, without any css, it seems like it may be working... care to verify that or add your styles, if there is anything covering the menu the click may not register...
– lucascaro
Nov 12 at 0:39
Thanks - I will check all css and see if I can find out why it is not working
– pbs
Nov 12 at 9:07
add a comment |
1
what kind of link is#Home
?
– guradio
Nov 12 at 0:22
2
Consider using consistent indentation in your code - it'll make debugging much easier (not only for others, but for you as well)
– CertainPerformance
Nov 12 at 0:29
2
I moved your code into a snippet and, without any css, it seems like it may be working... care to verify that or add your styles, if there is anything covering the menu the click may not register...
– lucascaro
Nov 12 at 0:39
Thanks - I will check all css and see if I can find out why it is not working
– pbs
Nov 12 at 9:07
1
1
what kind of link is
#Home
?– guradio
Nov 12 at 0:22
what kind of link is
#Home
?– guradio
Nov 12 at 0:22
2
2
Consider using consistent indentation in your code - it'll make debugging much easier (not only for others, but for you as well)
– CertainPerformance
Nov 12 at 0:29
Consider using consistent indentation in your code - it'll make debugging much easier (not only for others, but for you as well)
– CertainPerformance
Nov 12 at 0:29
2
2
I moved your code into a snippet and, without any css, it seems like it may be working... care to verify that or add your styles, if there is anything covering the menu the click may not register...
– lucascaro
Nov 12 at 0:39
I moved your code into a snippet and, without any css, it seems like it may be working... care to verify that or add your styles, if there is anything covering the menu the click may not register...
– lucascaro
Nov 12 at 0:39
Thanks - I will check all css and see if I can find out why it is not working
– pbs
Nov 12 at 9:07
Thanks - I will check all css and see if I can find out why it is not working
– pbs
Nov 12 at 9:07
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254552%2fanchor-only-firing-event-when-just-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
what kind of link is
#Home
?– guradio
Nov 12 at 0:22
2
Consider using consistent indentation in your code - it'll make debugging much easier (not only for others, but for you as well)
– CertainPerformance
Nov 12 at 0:29
2
I moved your code into a snippet and, without any css, it seems like it may be working... care to verify that or add your styles, if there is anything covering the menu the click may not register...
– lucascaro
Nov 12 at 0:39
Thanks - I will check all css and see if I can find out why it is not working
– pbs
Nov 12 at 9:07