Ognjen Regoje bio photo

MY NAME IS
Ognjen Regoje
BUT YOU CAN CALL ME OGGY


I make things that run on the web (mostly).
More /ABOUT me.

me@ognjen.io Twitter LinkedIn Instagram Github

Count the number of elements in a jQuery nested attributes container

To count the number of elements that is in a jQuery nested attributes container we can extend the plugin to have the following method (coffeescript):

  itemCount: ->
    @$items.filter(':visible').length

You would put that in the actual jquery.nested_attributes.coffee file. Then you can call:

  $("#selector").nestedAttributes("itemCount")
  • Update: this has been accepted to the core plugin so it’s no longer needed.

#jquery #jquery nested attributes #rails #technical