I have a syntax issue with writing the delegate function to make it work for each dynamiccaly inserted div.
The container is "column", and in "column" I insert many "dragbox" :
<div class="dragbox">
<h2>Actions
<button type="button">
<i class="fa fa-sort-desc"></i>
</button>
</h2>
<div class="dragbox-content">
content of the dragbox
</div>
</div>
So in each "dragbox" I have an "h2" and a "dragbox-content". My goal is to toggle the "dragbox-content" when I click on the "h2". Because the "dragbox" are inserted dynamically, I found out that I need to use the function "delegate" to make it work :
jQuery click not working for dynamically created items
jquery .delegate and dynamic content
Howver, my problem is that I don't know how to write it to make each "dragbox" have the same behaviour.
Here is what I tried so far :
$('.column').children('.dragbox').each(function(){
$(this).delegate("h2", "click", function(){
$(this).siblings('.dragbox-content').toggle();
}).end();
});
This works perfectly fine on static "dragbox", but not on dynamically inserted "dragbox". And I really need to use the function "each" because the toggle event is independent for each single "dragbox". I don't want all the dragboxes to toggle when I click on the header of one of them.
The libraries I used are jQuery and jQuery-ui.