I use http://silviomoreto.imtqy.com/bootstrap-select/ to make stylized selects.
.repeat select.selectpicker.color.col-xs-3 data-width="fit" action=text1 option data-content="<div class='colorpreview' style='background-color:red' ></div>" 1 option data-content="<div class='colorpreview' style='background-color:blue'></div>" 2 I process the data from select through
$('.color').on('changed.bs.select', function (e) { ... action = $(this).attr('action'); console.log(action); }); Then I wrote a copy of the last select:
$('.addText').click(function() { var count = $('.color').length; var next = count + 1; $('.color[action=text'+ count +']').clone(true).attr('action', 'text'+ next).appendTo('.repeat'); }); As a result, the element is copied, but when the value in the copied element changes, the parent's event is processed. This is detected by outputting the action attribute to the console (the action changes textN with each new element, where N = N + 1)
How to make the copied elements independent and self-sufficient?