Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:52:30+00:00 2026-05-15T15:52:30+00:00

Is there any way to prevent a click from an <a> triggering delegated click

  • 0

Is there any way to prevent a click from an <a> triggering delegated click handlers on its parent, while allowing the the <a>‘s default behavior to occur (navigating to the href).

Here’s an example that illustrates what I’m asking.

<div class="top">
    <div class="middle">
        <a href="google.com" class="link">link</a>
    </div>
</div>

And my JavaScript:

$(".top").delegate(".middle", "click", function(event) {
   alert("failure");
});

$(".top").delegate(".link", "click", function(event) {
   // ???
});

In this case, I want to be navigated to google.com when I click the link, but must NOT see the alert("failure") on my way out.

There are a few restrictions to the solution:

  1. All event handlers must be delegated off of $(".top"), as I potentially have thousands of these in the page.
  2. The navigation must be accomplished using browser default behavior, rather than window.location = $(this).attr("href") or similar

Using normal event binding, I could do an e.stopPropagation() in a click handler for the <a>, but that won’t work due to the nature of delegation. jQuery provides another method called .stopImmediatePropagation() that describes what I want (preventing other handlers on current element, in this case the element that holds the delegated handlers), but does not actually accomplish it in this case. That might be a bug in .delegate(), I’m not sure.

Returning false from the <a>‘s click handler will prevent the other handler from running, but will also do a .preventDefault(), so the browser will not navigate. Basically, I’m wondering what return false; does that e.stopImmediatePropagation(); e.preventDefault(); does not. Based on the docs, they should be equivalent.

For a live demo of the above code, here’s a JSFiddle: https://jsfiddle.net/CHn8x/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:52:31+00:00Added an answer on May 15, 2026 at 3:52 pm

    event.stopImmediatePropagation() is indeed what you’re after, but remember that order matters here since .delegate() listens at the same level, so you need to reverse your bindings, like this:

    $(".top").delegate(".link", "click", function(event) {
      event.stopImmediatePropagation();
    });
    $(".top").delegate(".middle", "click", function(event) {
      if(!event.isPropagationStopped())
        alert("failure");
    });
    

    Here’s a working version of your demo with this change

    The order you bound the handlers is the order they will execute, so you need that .link handler to execute and stop the propagation before the other handler runs, checking it with event.isPropagationStopped() or event.isImmediatePropagationStopped().

    This normally isn’t an issue at different levels, but since .delegate() is listening on the same element, it does matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to prevent Visual Studio from creating a VSMacros80 folder in
Is there any way to hide or encrypt JavaScript code to prevent people from
Is there any way to prevent the systemtray from auto hiding? I have this
Is there any way to prevent the user from scrolling the contents of a
Is there any way to prevent or detect a man-in-the-middle attack over plain HTTP?
When plotting a graph with a discontinuity/asymptote/singularity/whatever, is there any automatic way to prevent
Is there any way to capture the MouseDown even from the .NET 2.0 TextBox
I was wondering if there was a way to prevent a web page from
Is there any way to to list out the fields present in a table
Is there anyway to restrict by using pre-processing directives to prevent a project from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.