How to handle event on clicking a link in td?

How to handle event on clicking a link in td?

JanurajJanuraj Posts: 85Questions: 18Answers: 0
edited August 2020 in Free community support

Hi,
I have a td as defined below.
<td class=" cell-td">
<a href="#"class="test"></a>
</td>
I need to perform some action on the click of link "a.test".
I tried doing:
$('#profile-table tbody').on('click', 'a.test', function (e) {
e.preventDefault();
console.log('test1');
});

It is not logging the value.
can u please help me in understanding the event handler for the links in td?

Answers

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Two possibilities:

    <a href="#"class="test"></a>

    You need a space before the class. I think that is the most likely issue.

    The other is that your selector isn't picking anything up. A way to test that would be:

    console.log($('#profile-table tbody').length);
    $('#profile-table tbody').on( ... );
    

    If 0 is shown in the table, then either the element isn't in the document when that code is run, or tbody isn't present, or the id is wrong. We'd need a test case to say for sure.

    Allan

This discussion has been closed.