mardi 25 avril 2017

$(this).is(':checked') always returns false

I've got a collection of checkboxes and I'm trying to get the status of an individual checkbox when it is clicked. My best attempt so far has this in the coffeescript file:

if $('.boulderfist').length > 0
    unpressed = true
    $('.boulderfist').on "click", ->
        console.log($(this).is(':checked'))
        unpressed = false

And the boxes are created by this view:

      <%= a.collection_check_boxes(:seminar_ids, current_user.seminars, :id, :name) do |b| %>
        <tr>
          <td width="10%" class="boulderfist"><%= b.check_box %></td>
          <td><%= b.label %></td>
        </tr>
      <% end %>

The console prints "False" in every instance. This includes checkboxes that started checked and boxes that started unchecked.

I've also tried

console.log($(this).prop('checked'))

and

console.log($(this).checked)

and

console.log(this.prop('checked'))

and

 console.log(this.checked)

All of those other methods return undefined or errors.

Thank you for any insight.




Aucun commentaire:

Enregistrer un commentaire