I have several items in a list and want to highlight the one a user clicks on by applying some css style, maybe a background color etc.
My HTML looks like this:
If you don't need the active to be persistent here's a CSS way:
li:focus{ background: red; } li:active{ background: gold; }
Item 1 Item 2 Item 3 Now click here and see why it's not persistent.
in some situations the above might be useful - to only highlight the currently "click-active" item…