我正在尝试选择 ul 的第一个子级,然后将其删除,然后将其附加到该 ul 的末尾,但不幸的是我无法选择第一个子级。
这是代码
current = 0;
$(document).ready(function(){
width=951;
var totalSlides=$(".slider ul li").length;
$(".slider ul").removeAttr('width');
$(".slider ul").attr('width',width*totalSlides);
$('#next img').click(function(){
current -= width;
$(".slider ul").animate({"left":current+"px"}, "slow");
$(".slider ul").append($(".slider ul:first-child"));
//$('.slider ul:firstChild').remove();
});
});
最佳答案
您不需要 .remove()
help或.detach()
help将其附加到其他位置的节点。您只需调用 .append()
help 即可做到这一点或.appendTo()
help分别.after()
help和 .insertAfter
help 。例如:
$('ul li:first').insertAfter('ul li:last');
关于jquery - 用jquery选择第一个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4891579/