I am building a jQuery plugin to manage form collections. The plugin aims to add add, remove, move up and move down buttons to alter that collection.
A collection's root node always contains a selector, such as
.collection
.A button can be anything as soon as it has the
.add
class
I implemented min
and max
options, so add and remove buttons disappear accordingly. My problem comes up when I try to manage a collection of form collections: how to select only the add buttons that refers to the right collection?
To simplify the problem, look at the following HTML code:
<div class="collection">
<div>something</div>
<div>something</div>
<div>
<div class="add">+</div>
</div>
<div>something</div>
<div class="collection">
<div>something</div>
<div>something</div>
<div>
<div class="add">+</div>
</div>
<div>something</div>
</div>
</div>
Keep in mind that the button can be arbitrary deep: collection is built by an user and I don't know where can be the button in the dom. BTW, it is deeper than the .collection
, that's all I know.
How to select all add buttons until the second .collection
, but not further?
For those interested, this plugin is available (but in active dev) here.
.add
, select all.collection .collection .collection .add
, remove intersection – Mighellhtml
, would that be one.add
element ? – Triumvir