Okay
  Public Ticket #937647
jQuery Selector of wpDatatables
Closed

Comments

  •  2
    lennartwittmann started the conversation

    Hi support team,

    I have got a link column in my table. How can I capture a click on that link by jQuery? 

    I tried several thinks, but even the most general jQuery("a").click gets triggered when clicking any link within the table.

    I even added a class element in the <a> links in class.link.wpdatacolumn.php. So a link would print out <a class="wpdatatable" href="http://www.google,de">Link</a> and removed the target=_blank to remain in the current window.

    But no change either with jQuery(".wpdatatables").

    How can I select links in a wpdatatable by jQuery?

    Thanks a lot!

    Regards, Lennart


  • [deleted] replied

    Hi Lennart,
    Thank you for your purchase.

    If I understand correctly you want to click on a link and get that link with jQuery. E.g. cell data is www.google.com||Google and you want to get just www.google.com?

  •  2
    lennartwittmann replied

    Hi Milos,

    yes I want to process the href value of that link by some external jQuery/AJAX script. In order to do that I need to capture the click on a link within wpdatatables, e. g.

    jQuery('.wpdatatables').click(function(e) { ... // do something });

    But no matter what I define the click event will not get fired. Seems like the click already gets consumed by another script. 

    Question is: which jQuery-selector gets me the click on a link column within wpdatatables?


    BR Lennart


  • [deleted] replied

    Hi Lennart,

    You can use this code as example how to get href attribute from table:

    jQuery(window).load(function() {
        jQuery("#table_1").on('click', 'td > a', function() {
            var link = jQuery(this).attr('href');
            alert(link);
        }).DataTable();
    });
    
  •  2
    lennartwittmann replied

    WOW it worked! Thank your very much, Milos!

    You should published that on your homepage: Accessing table with external jQuery script!

    Thanks (again)!

    Lennart

  • [deleted] replied

    Hi Lennart,

    You are welcome. We'd greatly appreciate it if you could take a minute and leave a review on CodeCanyon on this link. Thanks!