We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Add/Remove CSS class to element (as opposed to “set”)

Home Forums Puzzles Add/Remove CSS class to element (as opposed to “set”)

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #34256
    Avatareabrosius
    Newbie

    I am wondering if there is a way in Verge to apply/remove a CSS className to an HTML element in an additive/subtractive fashion.

    Here is my setup:

    I have a button with ID: “buttonA” and three CSS classNames called “default”, “selected”, and “unavailable”.

    When the button needs to inherit the “default” className only, I am setting the className attribute to “default w-button”.
    When the button needs to inherit both the “default” and the “selected” classNames, I am setting the className attribute to “default selected w-button”.
    If I wanted to apply a third className to the button, like “unavailable”, I would have to set its className attribute to “default selected unavilable w-button”.

    My question is this: can I apply and remove a className to a button without needing to know what other classNames the button is currently inheriting?
    So instead of changing the className from “default w-button” to “default selected w-button”, can I just add the “selected” className to the button?

    Attachments:
    You must be logged in to view attached files.
    #34273
    Yuri KovelenovYuri Kovelenov
    Developer
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.