Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery not first child selector

I have the following markup:

<div class="feed-item">   <div class="date-header">2012-06-03</div> </div> <div class="feed-item">   <div class="todo">Todo</div> </div> <div class="feed-item">   <div class="meeting">meeting</div> </div> 

I want to show only the divs of a different class name e.g. class="todo" and keep the "date-header" visible. I have the following javascript"

$('.feed-cluster,.feed-item-container').not('div:first.date-header').not(className).slideUp(speed, function(){       $('.feed-cluster' + className + ',.feed-item-container' + className).slideDown(speed); }); 

Everything works fine except the bit where I am trying to exclude the first child with a class name of date-header:

.not('div:first.date-header') 

Can anyone suggest an alternative?

like image 668
dagda1 Avatar asked Jun 22 '12 07:06

dagda1


People also ask

How do you select all child elements except first?

To select all child elements except the first with JavaScript, we can use jQuery with the not pseudo-selector to select all elements except the first element. and we want to select the last 2 li elements, then we can write: $("li:not(:first-child)").

Is first child jQuery?

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.

How do you say not in jQuery?

jQuery :not() Selector The :not() selector selects all elements except the specified element.


1 Answers

$('div.date-header').slice(1); 

Should do it.

slice Is the fastest function!

Because :first is a jQuery extension and not part of the CSS specification, queries using :first cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method.

Alternative way, which still uses the querySelectorAll function:

$('div.date-header').not(':first'); 
like image 158
gdoron is supporting Monica Avatar answered Sep 18 '22 13:09

gdoron is supporting Monica