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?
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)").
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.
jQuery :not() Selector The :not() selector selects all elements except the specified element.
$('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');
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