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_<%=>">
          <td><%= check_box_tag "done[#{}]",, task.done, data:{
              remote: true,
              url: url_for(action: :toggle, 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>
    <% end %>

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


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(){

Related Articles