I am getting data from my database and displaying it on my HTML via php echo. Now I need to put a click function on specific tr with id breakrow
, but this click function is not working. I am using .on
function as suggested in documentation for dynamically added content. Also I dont see any error in console also.
Here is the sample code. (When I add same code directly into html page, its working as expected)
PHP Part:
echo '<div class="container" id="container">
<table class="gridtable" id="tableMain">
<thead>
<tr class="tableheader">
<th>customer</th>
<th>product</th>
<th>thedate</th>
<th>value</th>
</tr>
</thead>
<tbody>
<tr class="breakrow"><td>customer 01</td><td></td><td></td><td></td></tr>
<tr class="datarow"><td>customer 01</td><td>product 01</td><td>30 10 2017</td><td>974.57</td></tr>
<tr class="datarow"><td>customer 01</td><td>product 02</td><td>04 12 2017</td><td>634.50</td></tr>
<tr class="datarow"><td>customer 01</td><td>product 03</td><td>30 10 2017</td><td>974.57</td></tr>
<tr class="datarow"><td>customer 01</td><td>product 04</td><td>04 12 2017</td><td>634.50</td></tr>
<tr class="breakrow"><td>customer 02</td><td></td><td></td><td></td></tr>
<tr class="datarow"><td>customer 02</td><td>product 01</td><td>04 12 2017</td><td>634.50</td></tr>
<tr class="datarow"><td>customer 02</td><td>product 02</td><td>30 10 2017</td><td>974.57</td></tr>
<tr class="breakrow"><td>customer 03</td><td></td><td></td><td></td></tr>
<tr class="datarow"><td>customer 03</td><td>product 01</td><td>30 10 2017</td><td>974.57</td></tr>
<tr class="datarow"><td>customer 03</td><td>product 02</td><td>04 12 2017</td><td>634.50</td></tr>
<tr class="datarow"><td>customer 03</td><td>product 03</td><td>30 10 2017</td><td>974.57</td></tr>
</tbody>
</table>
</div>';
Jquery:
$( document ).ready(function() {
$('#tableMain').on('click', 'tr.breakrow',function(){
$(this).nextUntil('tr.breakrow').slideToggle(200);
});
});
can someone guide me how to resolve this ?