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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:01:36+00:00 2026-06-13T11:01:36+00:00

I have a problem with jQuery click() function. I use this function to programatically

  • 0

I have a problem with jQuery click() function.

I use this function to programatically click on a link which calls an ajax function that adds a new object to the database.

When I submit my form, a tr is added in the object datatable for my new object with new link and I want to programatically click on this new link to load object properties and display them.

The problem is that the new tr with td and link doesn’t exist in DOM and the function $.('#elem').click') doesn’t work.

I saw in others post that I have to bind click event with the new .on function like this :

$('#parent-items').on('click', 'elem', function() {
   // [...]
});

I don’t know what I have to write in place of […], at the end of my javascript code, I call the click function like this :

$('#myelem').click();

Thanks for your help

  • 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-13T11:01:37+00:00Added an answer on June 13, 2026 at 11:01 am

    Not that hard, actually. 🙂

    <table id="list">
        <tr>
            <td>John</td>
            <td><a class="btn-hi">Say Hi!</a></td>
            <td><a class="btn-bye">Say Goodbye!</a></td>
        </tr>
        <tr>
            <td>Lucy</td>
            <td><a class="btn-hi">Say Hi!</a></td>
            <td><a class="btn-bye">Say Goodbye!</a></td>
        </tr>
        <tr>
            <td>Sam</td>
            <td><a class="btn-hi">Say Hi!</a></td>
            <td><a class="btn-bye">Say Goodbye!</a></td>
        </tr>
    </table>
    
    <script>
    $('#list').on('click', 'a', function() {
        // Wrap the clicked <a> element with jQuery
        var $this = $(this);
    
        // Get the parent <tr> element
        var $tr = $this.closest('tr');
    
        // Get all (direct) children elements (<td>) that are inside the current <tr> element
        var $tds = $tr.children();
    
        // Get the text from the first <td> element in the current row
        var name = $tds.eq(0).text();
    
        // Get the type (class name) of clicked link
        var type = $this.attr('class');
    
        if (type == 'btn-hi') {
                alert( 'Hi, ' + name + '!' );
        } else if (type == 'btn-bye') {
                alert( 'Goodbye, ' + name + '!' );
        }
    });
    </script>
    

    Have a look at this demo in JSBin: http://jsbin.com/welcome/38776/edit

    The click event will get executed every time when user clicks on any <a> element that is inside <table id="list"> element. It’s called “event delegation” – http://api.jquery.com/delegate/

    So, you can dynamically add more rows to the table and everything will still work.

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

Sidebar

Related Questions

i have such problem that jQuery onclick event dont see click on link inside
I have a problem with jQuery selectors: $(ul.questions li).not(.title, .content).click().live('click', function(){ $(.inspector).slideToggle(); if($(this).hasClass(selected)) {
I have a problem with an animation in jQuery using ajax. On the click
I have some problem with my form. i want to use jquery ajax to
I have a problem with this Jquery function. The the simplifide code looks like:
I have a problem with this function: $(#contentdiv).click(function() { $(this).append(<div class='editable'>For some reason this
I am trying to use ajax like below; jquery code: $(a.generate).click(function(){ $.ajax({ data: {tag:
I made my first jQuery plugin attempt, but I have this problem/bug which I
I created a little jquery script and I have a problem to use (this)
I have a problem with one jQuery script. I use this code: <span class=follow

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.