Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting last-child of a div in IE8?

Tags:

Is there another way to get the last child of a div element other than using div:last-child, which does not work in IE8 at least?

like image 218
zsharp Avatar asked Feb 12 '09 21:02

zsharp


People also ask

What is Div last child?

The :last-child selector allows you to target the last element directly inside its containing element. 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.

How do I get the last child in HTML?

lastChild returns the last child node (an element node, a text node or a comment node). Whitespace between elements are also text nodes. lastElementChild returns the last child element (not text and comment nodes).

How do you except the last child in CSS?

The :last-child selector selects the last child. Combining these two above selector to excludes the last children (inner-div) of every parent div from the selection.


1 Answers

In jQuery it's easy:

$("div :last-child")

In pure CSS it can't be done.

Otherwise you're stuck with traversing the DOM in Javascript.

Also note the difference:

  • "div :last-child": every last child of a div; and
  • "div:last-child": every div that is a last child.
like image 167
cletus Avatar answered Nov 12 '22 22:11

cletus