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

  • Home
  • SEARCH
  • 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 6867547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:19:24+00:00 2026-05-27T03:19:24+00:00

I have a div with a nested link. The div has a delegate handler

  • 0

I have a div with a nested link. The div has a delegate handler for 'click', which alerts “Div”. The link within the div also has a delegate handler for 'click' wherein e.preventDefault(); is called before alerting “Link”. When I click the link, I see the “Div” alert, and the “Div” alert. I’m unclear why this is happening since I’m attempting to stop propagation from the link’s click handler.

JavaScript

$('body').delegate('.outer', 'click', function(e){
    e.preventDefault();
    alert('Div');
});

$('body').delegate('.outer a', 'click', function(e){
    e.preventDefault();
    alert('Link');
    // Note: I've also tried returning false (vs using preventDefault), per the docs
});

HTML

<div class="outer">
    <a href="#">Click me</a>
</div>
  • 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-27T03:19:24+00:00Added an answer on May 27, 2026 at 3:19 am
    1. PreventDefault doesn’t stop propagation, it stops the default action from being taken.
    2. Returning false/stopPropagation doesn’t work on delegated/live events because by the time it reaches the element on which the event is defined, it has already propagated up. It will stop propagation to elements higher in the DOM, but not prevent handlers at the same level (or lower) from being invoked. See this from the http://api.jquery.com/delegate documentation.

      Since the .live() method handles events once they have propagated to
      the top of the document, it is not possible to stop propagation of
      live events. Similarly, events handled by .delegate() will propagate
      to the elements to which they are delegated; event handlers bound on
      any elements below it in the DOM tree will already have been executed
      by the time the delegated event handler is called. These handlers,
      therefore, may prevent the delegated handler from triggering by
      calling event.stopPropagation() or returning false.

    3. If you don’t want the other handlers at the same level/DOM element to run, you can use stopImmediatePropagation. Note that the order in which the handlers are applied is important.

    4. You should probably be using on(), instead of delegate/live as of jQuery 1.7.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of links nested within a div. When one of those
I have a div which contains two nested divs, one that specifies a height
I have 2 divs nested within a parent div. Im having a problem setting
I have a div with two nested divs inside, the (float:left) one is the
I have a div and an iframe on the page the div has z-index:
I have a div in which a page is loaded with the DojoX Layout
I have a div with overflow:hidden , inside which I show a phone number
I have a series of DIVs on a page which each contain a nested
I have a nested form in a rails view that is called like this
So I have a nested div structure and I would like to get the

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.