Skip to content

Instantly share code, notes, and snippets.


havvg/collection.js Secret

Last active Dec 21, 2017
What would you like to do?
jQuery(function($) {
$(document).on('click', '.btn-add[data-target]', function(event) {
var collectionHolder = $('#' + $(this).attr('data-target'));
if (!collectionHolder.attr('data-counter')) {
collectionHolder.attr('data-counter', collectionHolder.children().length);
var prototype = collectionHolder.attr('data-prototype');
var form = prototype.replace(/__name__/g, collectionHolder.attr('data-counter'));
collectionHolder.attr('data-counter', Number(collectionHolder.attr('data-counter')) + 1);
event && event.preventDefault();
$(document).on('click', '.btn-remove[data-related]', function(event) {
var name = $(this).attr('data-related');
event && event.preventDefault();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.