Albert Albert - 1 year ago 61
jQuery Question

JQuery.on() click listener not working as expected

I have the following HTML structure:

<table class="table table-hover js-integrations js-radio-rows">
<th>Modified Date</th>
<!-- Start load by ajax -->
<tr class="clickable">
<td class="js-integration-option">
<input type="radio" value="20" name="integration_id" class="pseudo-radio sr-only">
<label class="icon-lg" for="http-radio"></label>
<img align="absmiddle" src="imglocation" />
Some Title
<span class="file-size">
Owner Le Own
<!-- End load by ajax -->

And I have this piece of jQuery.

jQuery('.js-radio-rows').on('click', 'tr', function() {

When I click on the clickable row,
does not fire. Any ideas what I'm doing wrong? Could it be because the rows are loaded by ajax? This happens long after document ready is called, since it depends on something else that is clicked.

Answer Source

If .js-radio-rows table is not available on document.ready event, this will not work. Try setting document as delegate for the event:

jQuery(document).on('click', '.js-radio-rows tr', function() {