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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:20:52+00:00 2026-05-27T02:20:52+00:00

Suppose I have the following HTML: <div class=container> <span class=remove>remove</span> </div> and jquery: $(.container).delegate(.remove,

  • 0

Suppose I have the following HTML:

<div class="container">
  <span class="remove">remove</span>
</div>

and jquery:

$(".container").delegate(".remove", "click", function() {           
    alert('yes');       
});

This works, but now I have HTML like:

<div class"container">
  <div>
     <span class="remove">remove</span>
  </div>
</div>

or even

<div class"container">
  <div>
     <div>
        <span class="remove">remove</span>
     </div>
  </div>
</div>

So how can I make the jquery work in this case, so that if finds the .remove element in a hierarchy of elements and make the click event work?

NOTE: I’m adding the elements dynamically (using clone function)!

  • 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-27T02:20:53+00:00Added an answer on May 27, 2026 at 2:20 am

    This will still work. As long as the element you’re delegating the event to is an ancestor of the element, the element will receive the event.

    An exception to this is where an element which is a more direct ancestor stops the propagation of the event using event.stopPropagation(), event.stopImmediatePropagation(), or by returning false in it’s handler;

    $(".container").delegate(".remove", "click", function() {           
        // This will never get executed, as the first handler cancels the propagation.
        alert('yes');       
    });
    
    $(".container > div").delegate(".remove", "click", function(e) {           
        // This handler get the event first as it is closer to the source of the event.
        e.stopPropagation();
    });
    

    FYI, if you’re using jQuery > 1.7, you should consider using the new on() method as on() was implemented to disperse the confusion over live(), delegate() and bind(). It is expected that these older methods will be depreciated in 1.8. The following is equivilent for what you’re currently using;

    $(".container").on("click", ".remove", function(e) {           
        alert('yes');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have this following code in HTML - <div id=pattern> <span class=a>Content</span> </div>
Suppose I have the following HTML: <div id=test> <span style=display:inline;>foo</span> <span style=display:none;>bar</span> <span style=display:inline;>baz</span>
Suppose I have the following HTML and js <div> <div class=testdiv id=test1>test</div> <div class=testdiv
Suppose I have the following html: var testString = ' <span id='id'> <div> <table>
Fellow JQuery hackers, hello :-) Suppose you have the following code: $('.links').click(function(){ //Do something
Suppose I have the following HTML code: <div id=container style=width: 960px> <div id=help_panel style=width:
I have the following JQuery Code concerning my tabs : $(#onglet>ul>li).click(function(){ $(#onglet ul li).removeClass('Selectionne').addClass(OngletPrincipal);
Suppose I have the following html, and no CSS <div> here is some content
I have the following element in HTML: <div class=window iname=win0> <div class=title prop=title> </div>
I have the following jQuery script... $(function() { $('.eventWrapper').bind('click', function(event) { var srvName =

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.