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?
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.
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).
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.
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.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