Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the element is not the first-child?

How do you know if the current element is not the first-child?

It should work with $(this), for example:

$("li").click(function(e) {     if (/* $(this) is not the first-child */)     {         /* do something */     } }); 
like image 542
James Avatar asked Sep 09 '10 12:09

James


People also ask

How do you choose not your first child?

Use the :not(selector) Selector Not to Select the First Child in CSS. We can use the :not(selector) selector to select every other element that is not the selected element. So, we can use the selector not to select the first child in CSS. We can use :first-child as the selector in the :not(selector) selector.

What is not first child?

ul:not(:first-child) means literally "any ul element that is not first child of its parent", so it won't match even the 1st ul if it's preceded by another element ( p , heading etc.). On the contrary, ul:not(:first-of-type) means "any ul element except the 1st ul in the container".

Is pseudo selector The first child?

The first-child is a pseudo class in CSS which represents the first element among a group of sibling elements. The :first-child Selector is used to target the first child element of it's parent for styling. Example: HTML.

How do I get CSS only for my first child?

The :first-child selector is used to select the specified selector, only if it is the first child of its parent.


1 Answers

You can do this just to test an element if it's the first child: $(this).is(':first-child'). Other selectors like :last-child would work too.

like image 133
slikts Avatar answered Sep 24 '22 00:09

slikts