用jQuery选择第一个孩子 [英] select first child with jquery

查看:120
本文介绍了用jQuery选择第一个孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择ul的第一个孩子,然后将其删除,然后将其附加在该ul的末尾,但是很遗憾,我无法选择第一个孩子.

I am trying to select first child of ul and then remove it and then append it in the end of that ul but unfortunately i can not selet first child.

这是代码

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() 帮助 .detach() 帮助 将其附加到其他地方的节点.您只需调用> .append() help .appendTo() help .insertAfter 帮助 .例如:

You don't need to .remove()help or .detach()help a node to append it somewhere else. You can do it by just invoking .append()help or .appendTo()help respectively .after()help and .insertAfterhelp. For instance:

$('ul li:first').insertAfter('ul li:last');

演示: http://www.jsfiddle.net/KFk4P/

这篇关于用jQuery选择第一个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆