I have following markup
<div class="cloneLayoutSelect">
<div class="col2">
<select name="ingredients[0][name]" id="ingredient" class="select" data-multi-column="true" data-label="Ingredient">
<option value="0">Carrot</option>
<option value="1">Milk</option>
<option value="2">Yogurt</option>
</select>
</div>
<div class="col2"><input name="ingredients[0][quantity]" id="quantity" class="form-control" placeholder="Quantity" data-multi-column="true" data-label="Quantity" value="" type="text"></div>
<div class="col1 text-right"><button class="btn btn-default multi-column-2"><i class="fa fa-plus"></i></button></div>
<div class="clearfix clear"></div>
</div>
On click of button.multi-column-2 I want to
- Get all elements within the parent div
cloneLayoutSelectand which has the data attribute ofdata-multi-column="true" - Get value of
data-labelof individual element from the previous match - Get
input/select/radio/checkboxvalue of individual element from the previous match
I tried the following:
var elements = $('*[data-multi-column="true"]');
$.each(elements, function(index, htmlElement) {
var element = $('<div><div/>').html(htmlElement).contents();
});
Although it returns me desired result, i have two problems with this
- It searches in all html markup, which is not what i want, I want to only search it within its parent element
cloneLayoutSelect. - It removes all html within
<div class="col2">
Any help or pointers is appreciated.
Thanks.
find()on those elements.