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 6877237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:34:35+00:00 2026-05-27T04:34:35+00:00

I used .stopPropagataion() to stop the bubbling in <li class=article> when clicking on the

  • 0

I used .stopPropagataion() to stop the bubbling in <li class="article"> when clicking on the <a> tag.

$(document).ready(function(){
   $(".article a").click(function(e) {
        e.stopPropagation();
   });
});

With this HTML:

<li class="article" onlick="javascript:somefunction();">
   <div id="div_id">
      <a>Some link</a>
   </div>
</li>

Everything worked fine, but then I used $('#div_id').load("div_html.html") to load some content into the div dynamically. Now my .stopPropagation() doesn’t stop the bubbling. Why isn’t it working anymore?

  • 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-27T04:34:35+00:00Added an answer on May 27, 2026 at 4:34 am

    The problem is that when you update the content of the div, you destroy all of the elements that were inside it (including any event handlers attached to them). Your code is hooking the click event on the a elements that are in the div as of when your code runs; new a elements in the div will not be hooked up.

    In your case, you’re better off using delegate (live example, with load):

    $(document).ready(function(){
       $(".article div").delegate("a", "click", function(e) {
            e.stopPropagation();
       });
    });
    

    That hooks click on the div instead. When the click occurs, it bubbles from the link to the div, where the click handler created by jQuery examines it to see if it was actually a click on any a element. If so, it stops the click.

    As of jQuery 1.7, the new recommended syntax is on instead:

    $(document).ready(function(){
       $(".article div").on("click", "a", function(e) {
            e.stopPropagation();
       });
    });
    

    Note that the order of arguments is different from delegate, but other than that it does the same thing.


    I’d recommend avoiding combining old-style DOM0 handlers (event handler attributes) with new-style DOM2 code (your handler attached with jQuery). In many browsers, the two mechanisms are somewhat separate and may not play as nicely together as you’d like.

    Two other comments on this:

    onlick="javascript:somefunction();"
    
    1. It’s onclick, not onlick (you’re missing the c)
    2. You don’t use the javascript: pseudo-protocol on event handler attributes, only hrefs. Just remove that part. (Why doesn’t it cause an error? Because purely by coincidence, it’s valid JavaScript — you’re defining a label you never use.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: var originalBorder = container.css("border"); container.hover(function(event) { event.stopPropagation(); $(this).css("border", "1px solid
i tried using stopPropagation() without luck. I've this structure: <div class=logos> </div> I've a
i used this code: List<string> lists=new List<string>(apple,orange,banana,apple,mang0,orange); string names; names=lists.Distinct() is that correct?
I have a span in my page once. I have used hover function to
Used this tutorial I have installed jogl, jocl, gluegen, joal libs and added its
i used this code, but this codes only removes the duplicates on the list
For some reason clicking the document isn't working in Chrome (the closeQuickView is not
I have used event.preventDefault() and event.stopPropagation() in various places but it always seems to
Used http://www.ilbcfreeware.org/software.html - I only get static from the files that ilbc_test.exe creates. Does
I used this answer: Install xCode 3.2.3 w/ iPhone SDK 4, get "Base SDK

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.