javascript - Fetch and append element at last using jQuery -
i have div parent element class .carousel-inner. within parent div, there children elements. want take 2nd (child) element , append element @ last. getting , appending second element this.
var = $(".carousel-inner").children()[1]; $(".carousel-inner").append(a);
now append element, removes element second position , append @ last. want keep element second position well. how can it?
using clone()
after find element. , make variable
var = $(".carousel-inner").children()[1], b = $(a).clone(); $(".carousel-inner").append(b);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="carousel-inner"> <div class="child"> </div> <div class="child"> clones </div> <div class="child"> c </div> </div>
or clone element before appending :
var = $(".carousel-inner").children()[1] $(a).clone().appendto('.carousel-inner');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="carousel-inner"> <div class="child"> </div> <div class="child"> clones </div> <div class="child"> c </div> </div>
Comments
Post a Comment