I have two buttons that are part of a form selector, option A option B etc… I need to be able to tell the buttons which state to display when pressed. The buttons set a variable with javascript :smile
setPackageOption(1)
Could I tell them when pressed to stay in the pressed state?
You could set the className onclick to a pre-set class of pressed / not-pressed.
You can’t really set the selector (:hover or :active or :visited ) via javascript as this is not really a rule but a state that can be applied to any element. What you should do is just create rules for different states and then change the className according to which state you want to display.
Look at element.classList.contains and element.classList.toggle for the javascript to manipulate selectors.
Thanks, this looks great and have got the background colours working fine by the classes already set on the elements. I presume I need to remove the hard coded element classes now and set them by script so when the button is pressed the class name changes.
Sorry for my lack of javascript! how do I do that?