Änderung der inneren Elemente id während der Klon
Ich bin ein Klon eines DIV-Elements auf die Schaltfläche klicken, ich bin in der Lage, ändern Sie den Wert der ID des DIV-Elements bin ich Klonen. Aber ist es möglich, ändern Sie die id von dem inneren element.
In der unten code ich bin ändern der Id von #selection
während das Klonen, muss ich dynamisch ändern Sie die id -#select
.
<div id="selections">
<div class="input-group" id="selection">
<span class="input-group-addon">
<i class="icon wb-menu" aria-hidden="true"></i>
</span>
<select class="show-tick" data-plugin="select2" id="select">
<option>True</option>
<option>False</option>
</select>
</div>
</div>
<button class="btn btn-primary" type="button" style="margin-left: 30px;">
Add new selection
</button>
JS unten
$(function() {
//on click
$("body").on("click", ".btn-primary", 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);
//append clone on the end
$("#selections").append(clone);
});
});
InformationsquelleAutor Jeyaprakash | 2015-10-30
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ja.. es ist durchaus möglich, wie folgt:
InformationsquelleAutor vijayP
Müssen Sie ändern Sie alle Kinder-ID manuell ein.
Entweder ändern Sie es für nur einen:
Oder ändern, dass alle Kinder mit so etwas wie: jQuery verändern das id-Attribut für alle Kinder
InformationsquelleAutor Florian