Get a <tr> ID which is generated dinamically

I need to get the id from the checkbox below

<% @task.each do |task| %>

        <tr id="tr_<%= task.id%>">
          <td><%= check_box_tag "done[#{task.id}]",task.id, task.done, data:{
              remote: true,
              url: url_for(action: :toggle, id: task.id, checked: task.done),
              method: "POST"
          } %> </td>
          <td><%= task.title %></td>
          <td><%= task.detail %></td>
          <td><%= task.task_date.strftime('%d/%m/%Y') %></td>
          <td><%= button_to('Show', task_path(task) , :class => 'btn btn-default', :method => :get)  %></td>
          <td><%= button_to('Edit', edit_task_path(task), :class => 'btn btn-primary',:method => :get)  %></td>
          <td><%= button_to('Remove', task_path(task), :class => 'btn btn-danger', method: :delete, data:{ confirm: 'Are you sure?' }) %></td>
        </tr>
    <% end %>

My JS is running as expected but i didn't figure out how to do it dinamically.

$("#tr_37").change(function(){
         $(this).hide();
     });

Answers 1

  • Do you want hide tr when checkbox changed?

    I think you need catch event of checkbox when changed

    $("tr input[type='checkbox']").change(function(){
         $(this).closest("tr").hide();
    });
    

Related Articles