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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:18:28+00:00 2026-05-27T09:18:28+00:00

I have to following HTML: <ul class=ulclass> <li class=liclass> …some more nesting <a href=somelink>somelink</a>

  • 0

I have to following HTML:

<ul class="ulclass">
   <li class="liclass">
      ...some more nesting
           <a href="somelink">somelink</a>
      ....close nesting
   </li>
   <li class="liclass">
   ...

</ul>

There is a click event on each li from the class “liclass”, so I stop the bubbling from the anchor with (presumably <div> is inside of .liclass):

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

Now I add more <li class="liclass"> with Ajax .load. The stopPropagation works for the static “.liclass” but not for the dynamically added.
Assume that the code for <ul class="ulclass"> is there when the page is loaded.
Can you please let me know how the change .delegate in order to stop the bubbling for the dynamically added .liclass.

  • 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-27T09:18:28+00:00Added an answer on May 27, 2026 at 9:18 am

    Place another delegate handler on whatever contains the dynamically created elements, in this case the ul, to stop the propagation.

    $("ul.ulclass").delegate(".liclass div", "click", function(e) {
              e.stopPropagation();        
    });
    
    $("ul.ulclass").delegate(".liclass", "click", function(e) {
              // main code for each li element    
    });
    

    Because they’re both delegate methods on the same element, the e.stopPropagation() should work to prevent the handler even though the event has already bubbled up.

    JSFIDDLE DEMO

    Updated the demo to show it working with dynamic elements.


    An alternative would be to simply bind handlers directly to your dynamically created div elements.

    So if you’re using .load(), I assume you’re wiping out the old content and replacing it with new. In that case, in the callback, just select the divs, and rebind the handler.

    $("ul.ulclass").load('/whatever/', function() {
          // shortcut to binding a handler with stopPropagation and preventDefault
        $(this).find('li.liclass div').bind('click', false);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a
I have the following HTML: <tr> <td class=ui-widget-content> <a title=Edit href=/Administration/Menus/Edit/001W class=editLink ui-button ui-widget
I have the following HTML: <div class=menu> <a class=main-nav-item href=home>home</a> <a class=main-nav-item-current href=business>business</a> <a
Lets say I have the following HTML... <a class=active href=#section1>Link 1</a> <a href=#section2>Link 2</a>
I have a simple question. I have the following html code <a href=# class=purchase>
Assuming, I have the following HTML: <ul class=topnav> <li class=><a href=/>Page 1</a></li> <li class=><a
I have the following html <div class=sub> <a href=# id=people>People</a> </div> which has the
I have the following HTML... <body onload=draw();> <p><a href=><canvas class=demo2 width=6 height=12>Fallback</canvas> Back to
I have following generrated HTML, and I want to add some CSS class to
I have the following HTML <tbody class=t_bdy> <tr class=Quotation_List_td> <td class=item><a class=button2 crm_insert href=#>Insert</a><a

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.