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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:48:56+00:00 2026-06-03T05:48:56+00:00

I want to use the ‘On’ function to attach a event because the others

  • 0

I want to use the ‘On’ function to attach a event because the others are deprecied(live, delegate,click…).

But the problem is : if we generate objects, we need to use a selector in parameters and this parameter is a string!!

Sample :
(context : dynamic table)

//Wrong way

$("#dataTable tbody tr").on("click", function(event){
    alert($(this).text());
});

//Good way

$("#dataTable tbody").on("click", "tr", function(event){
    alert($(this).text());
});

Now How I do if I want use ‘find’ method in order to avoid that

    // ?? (find div)
    $("#dataTable tbody").on("click", "tr > ul > li > ul > li > div", function(event){
            alert($(this).text());
        });

   // What I would like to do
    $("#dataTable tbody").on("click", $(this).find("div"), function(event){
            alert($(this).text());
        });

   //and I don't want to do this :
    $("#dataTable tbody").find('div').on("click", function(event){
            alert($(this).text());
        });

Thank you !

  • 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-06-03T05:48:57+00:00Added an answer on June 3, 2026 at 5:48 am

    The working equivalent to:

    // What I would like to do
    $("#dataTable tbody").on("click", $(this).find("div"), function(event){
        alert($(this).text());
    });
    

    is…

    // What I would like to do
    $("#dataTable tbody").on("click", 'div', function(event){
        alert($(this).text());
    });
    

    If you to target div‘s inside the nested list, then you might be able to get away with:

    // What I would like to do
    $("#dataTable tbody").on("click", 'ul ul div', function(event){
        alert($(this).text());
    });
    

    … but it depends if you have other ul‘s in your tbody; you only need to be specific enough in your selector to remove the other elements from consideration. Very rarely would you need to be as specific as tr > ul > li > ul > li > div, and in that case it’d be best to apply a class to an element nearer the div (or the div itself) and select around that instead.

    Also note that it is only live() that is depreciated. At the time of writing (1.7.2) delegate() is not, although I believe it will be in 1.8.

    There is no talk of depreciating click() or it’s shortcut counterparts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use Kendo ui window, but I can't see what the problem is.
I want use from multiple upload image in codeigniter but problem is here that
I want use JQuery mobile for the front-end of my mobile application, but I
I have to use boost::spirit for parsing, and I want use phrase_parse function :
Example I want use the_excerpt in two locations. On functions.php I add function new_excerpt_length($length)
Im trying to do simple audio player, but I want use a image(icon) as
I want use a typedef struct that isn't already defined, but it is later.
I want use the Scintilla controls and the RadControls for Winforms, but I do
I want use many bitmap for my game canvas. I can't Recycle bitmaps, because
I want use task_for_pid() and attach to another process and then change its memory

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.