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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:06:21+00:00 2026-05-16T14:06:21+00:00

i’m having a bit of a prblem with the jquery click function, below is

  • 0

i’m having a bit of a prblem with the jquery click function, below is part of the layout of my code:

<td id="01" class="day-main-diary">
    <div title="sdfsdf" class="diary-event ui-corner-all">
        <span id="delete"></span>
        <div class="diary-event-title ui-corner-all">
            sdfsdf
        </div>
        <div class="diary-event-body ui-corner-all">
            <p class="hyphenate">sdfsdf</p>
        </div>
    </div>
</td>

The title, text in diary-event-title and text in diary-event-body are all dynamically generated and the class ‘day-main-diary’ has a click function bound to it (the actual code in the js file is:

$('.day-main-diary').click(function(){
   // Code is here
}

i am looking for a way for a click event to be recognised on the span with the id of ‘delete’,
amongst other things i have tried

$('.day-main-diary #delete').click(function(){

and

$('#delete').click(function(){

however, each time it completely ignores this event and always calls the day-main diary click event.

can anyone help me? i will be eternally greatfull
-Matt

  • 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-16T14:06:22+00:00Added an answer on May 16, 2026 at 2:06 pm

    First, remember that there can only be one #delete ID on the page. If there’s more than one, you’ll have issues, and should make it a class .delete.

    If the #delete element isn’t present when the page loads (dynamic) you can use .live(), which will take care of handling the event for you, no matter when you add the element.

    $('#delete').live('click', function(){
               ...
     });
    

    But note that this will still fire the event on the .day-main-diary as well.

    One other option would be to call .delegate() on the .day-main-diary (as long as it is there when the page loads). This is similar to .live() but is more localized.

    $('.day-main-diary').delegate('#delete', 'click', function() {
            ...
    });
    

    This also will fire the click on the .day-main-diary. Not sure what the expected behavior is.

    • http://api.jquery.com/live/
    • http://api.jquery.com/delegate/

    Yet another option would be to test the e.target of the click in the .day-main-diary click handler. If it is the #delete do one thing, if not, do another.

    $('.day-main-diary').click(function( e ) {
        if(e.target.id === 'delete') {
           // run code for the delete button
        } else {
           // do something else 
        }
    });
    

    Otherwise, still assuming that the #delete is dynamic, you can bind the .click() when you create it.

    $('<span id="delete">delete</span>').click(function( e ) {
           // your code
           // uncomment the line below if you don't want the 
           //    click event to fire on .day-main-diary as well
           // e.stopPropagation()
    })
    .appendTo('day-main-diary');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.