<ul class="swiper-wrapper">
<li class="swiper-slide">
<img src="./images/banner-1.jpg" alt="">
<span class="slider-text"></span>
</li>
<li class="swiper-slide">
<img src="./images/banner-2.jpg" alt="">
<span class="slider-text"></span>
</li>
<li class="swiper-slide">
<img src="./images/banner-3.jpg" alt="">
<span class="slider-text"></span>
</li>
<li class="swiper-slide">
<img src="./images/banner-4.jpg" alt="">
<span class="slider-text"></span>
</li>
</ul>
I want to copy the li
tag itself including all sub-elements to the front of the first li
tag. jquery has a simple way to write it.
var swiperPic = $(".swiper-slide")
var liHtml = swiperPic.eq(swiperPic.length - 1).html()
swiperPic.eq(0).before("<li class="swiper-slide">" + liHtml +"<li>")
What I think of is to copy all the child elements under the li
tag but not the li
tag itself.
高洛峰2017-06-05 11:14:54
$(selector).children(selector)
is used to return the child elements of each element in the matching element set.
给我你的怀抱2017-06-05 11:14:54
var swiperPic = $(".swiper-slide");
swiperPic.eq(0).before(wiperPic.eq(swiperPic.length - 1).children().clone());