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.
Here is code
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();
});
});
It is a jQuery Selector used to select every element that is the first child of its parent. Return Value: It selects and returns the first child element of its parent.
The :first selector selects the first element. Note: This selector can only select one single element. Use the :first-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the first element in a group (like in the example above).
grab the second child: $(t). children(). eq(1);
jQuery | :nth-child() Selector jQuery :nth-child() Selector Selects all elements that are the nth-child of their parent. Syntax: $("Element:nth-child(Index/even/odd/equation)") Values: Index: Index provided. Index starts from.
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 .insertAfter
help. For instance:
$('ul li:first').insertAfter('ul li:last');
Demo: http://www.jsfiddle.net/KFk4P/
Any of these will work:
$('ul > li:first')
$('ul > li:first-child')
$('ul > li:eq(0)')
$('ul > li:nth-child(1)')
$('ul > li').eq(0)
$('ul > li').first()
$('ul > li')[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With