I\'m doing a clone of a DIV element on button click, I\'m able to change the value of ID of the DIV element I\'m cloning. But is it possible to change the id of the inner elemen
Use the class .show-tick
and the .children()
method to locate the element:
clone.children('.show-tick').attr('id', 'select-' + length);
$(function() {
//on click
$(".btn-primary").on("click", function() {
alert($(".input-group").length)
var
//get length of selections
length = $(".input-group").length,
//create new id
newId = "selection-" + length,
//clone first element with new id
clone = $("#selection").clone().attr("id", newId);
clone.children('.show-tick').attr('id', 'select-' + length++);
//append clone on the end
$("#selections").append(clone);
});
});