YouTip LogoYouTip

Sel Nthlastoftype

## jQuery Misc [jQuery noConflict() Method](#) Method")(#) ## jQuery Examples (#) ## jQuery Reference (#)(#)(#)[jQuery HTML / CSS Methods](#)(#)(#)(#)(#) ## jQuery Plugins (#)(#)(#)(#)(#)(#)(#) jQuery :nth-last-of-type() Selector ## Definition and Usage The :nth-last-of-type(n) selector selects all elements that are the nth child, relative to their parent, of the same type (tag name). **Note:** n accepts integers (1, 2, 3, ...), keywords (odd, even), and formulas (2n+1, 2n, ...). Tip: Use :nth-last-of-type(1) to select all elements that are the last child, relative to their parent, of the same type! ## Syntax ```css :nth-last-of-type(n) ## Parameter | Parameter | Description | |-----------|-------------| | n | Required. Specifies which child to select. Possible values:1 - selects the first element2 - selects the second element3 - selects the third element... - and so onodd - selects every odd element (1st, 3rd, 5th...)even - selects every even element (2nd, 4th, 6th...)2n - selects every even element (2nd, 4th, 6th...)2n+1 - selects every odd element (1st, 3rd, 5th...)3n - selects every 3rd element (3rd, 6th, 9th...)3n+1 - selects every 3rd element starting from the 1st (1st, 4th, 7th...) | ## jQuery Selectors (#) ## jQuery CSS Classes (#) --- ## More Examples ### Example Select the second p element of its parent, counting from the last child: $(document).ready(function(){ $("p:nth-last-of-type(2)").css("background-color","yellow"); });

This is a heading

The first paragraph.

The second paragraph.

The third paragraph.

The fourth paragraph.

(#) ### Example Select all p elements that are the second element of its parent, counting from the last child: $(document).ready(function(){ $("p:nth-last-of-type(even)").css("background-color","yellow"); });

This is a heading

The first paragraph.

The second paragraph.

The third paragraph.

(#) --- Markdown Content:
← Sel OnlyoftypeSel Nthoftype β†’