Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show first child of element without a specific class using jQuery

I am trying to show the first child of an element which does not have a class of "submitted"

So something like

$('#menu li:first-child:not(".submitted")').show();

HTML:

<ul id="menu">
   <li class="submitted">stuff here</li>
   <li class="submitted">stuff here</li>
   <li>stuff here</li> <!-- This one needs to be shown -->
   <li>stuff here</li>
   <li>stuff here</li>
</ul>

Any ideas??

like image 842
Tom Avatar asked Dec 13 '11 12:12

Tom


People also ask

How do I skip the first child in CSS?

By using the :not(:first-child) selector, you remove that problem. You can use this selector on every HTML element.

How do you select an element without a class?

The :not CSS pseudo-class can be used to select elements that do not contain a specific class, id, attribute etc.

How do you select the first child of a class in CSS?

The :first-of-type selector in CSS allows you to target the first occurence of an element within its container. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.


2 Answers

$('#menu li:not(.submitted):first')
like image 51
Sjoerd Avatar answered Oct 15 '22 09:10

Sjoerd


Try this:

$('#menu li:not(".submitted"):first').show();

http://jsfiddle.net/WDx3M/

like image 20
hasser Avatar answered Oct 15 '22 08:10

hasser