I have a function that changes a table in a list, so far so good, but when the function changes in js it stops working, if I reload the page it works but if I change the DOM nothing. Can you help me?
$(document).ready(function() {
$('#table-list tbody tr').click(function(event) {
if(event.target.type == 'checkbox'){
}else{
$(':checkbox', this).trigger('click');
}
});
$('#ul-list li').click(function(event) {
var checkbox_type = $(event.target).find("input[type='checkbox']").attr('name');
if(checkbox_type){
$(':checkbox', this).trigger('click');
}
});
});
These are the two events that should always be active. But if I change the table to ul not it works
So let me explain better, I have a table like this:
<table id="table-list">
<tbody>
<tr>
<td><input type="checkbox" name="1" /></td>
</tr>
<tr>
<td><input type="checkbox" name="3" /></td>
</tr>
</tbody>
</table>
Then by clicking on a button I convert it to a list by removing the table from the DOM and inserting this:
<ul id="ul-list">
<li>
<input type="checkbox" name="1" />
</li>
<li>
<input type="checkbox" name="3" />
</li>
</ul>
Now I want if I try to click on the list this function should start:
$('#ul-list li').click(function(event) {
var checkbox_type = $(event.target).find("input[type='checkbox']").attr('name');
if(checkbox_type){
$(':checkbox', this).trigger('click');
}
});
instead no.