Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Select last

1 view
Skip to first unread message

Andrew Poulos

unread,
May 12, 2021, 10:24:37 PM5/12/21
to
I have a number of BUTTON elements. One of the elements will always have
a '.last-btn' class (and it may well be the last element). How can I
select the "last" element but never the one with 'last-btn'?

For example, if the elements were in this order
b-1, b-2, b-3, b-last
or in this order
b-1, b-last, b-2, b-3
b-3 would be selected.

These fail :-(
div > button:last-child, button:not(.last-btn)
div > button:last-child, div > button:not(.last-btn)

Andrew Poulos

Thomas 'PointedEars' Lahn

unread,
May 13, 2021, 8:00:06 AM5/13/21
to
The comma between selectors acts like an OR operator.

Use

div > button:last-child:not(.last-btn)

instead.

However, you should avoid formatting based on element type and position, and
use classes instead.

See also: <https://cssguidelin.es/>

--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

James Kirk

unread,
May 13, 2021, 2:59:39 PM5/13/21
to
In Message: <ofednRaSktRCEAH9...@westnet.com.au>
Andrew Poulos <ap_...@hotmail.com> wrote:

> I have a number of BUTTON elements. One of the elements will always
> have a '.last-btn' class (and it may well be the last element). How
> can I select the "last" element but never the one with 'last-btn'?

> For example, if the elements were in this order
> b-1, b-2, b-3, b-last
> or in this order
> b-1, b-last, b-2, b-3
> b-3 would be selected.

Is your intent to select b-3 in both examples?

https://codepen.io/noneyainvalid/embed/zYZqqOM/?theme-id=modal

[snip]

If not then the example Thomas provided should do what you want.

--
J𝕒𝕞𝕖𝕤 𝕂𝕚𝕣𝕜


0 new messages