Ognjen Regoje bio photo

Ognjen Regoje
But you can call me Oggy


I make things that run on the web (mostly).
More ABOUT me and my PROJECTS.

me@ognjen.io LinkedIn

Count the number of elements in a jQuery nested attributes container

#jquery #jquery nested attributes #rails #technical

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.