• Select last

    From Andrew Poulos@21:1/5 to All on Thu May 13 12:24:29 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas 'PointedEars' Lahn@21:1/5 to Andrew Poulos on Thu May 13 14:00:03 2021
    Andrew Poulos 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.

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

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kirk@21:1/5 to Andrew Poulos on Thu May 13 14:59:33 2021
    In Message: <ofednRaSktRCEAH9nZ2dnUU7-I_NnZ2d@westnet.com.au>
    Andrew Poulos <ap_prog@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š•’š•žš•–š•¤ š•‚š•šš•£š•œ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)