Skip to content
Advertisement

How to add CSS after click through javascript and remove it if not clicked

I have encountered a problem with javascript clicking to change CSS!

I hope that the outer frame and text of the clicked option can be thickened after clicking, but the ones that are not selected should not be thickened! I have tried several ways of writing, but I still don’t know how To complete this requirement, I hope to get everyone’s help, thank you.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

You need to toggle the class, you can do that by removing it from every item and only setting it to the selected one:

JavaScript

Also you have a CSS specificity issue:

when using only .bold, the border would be overriden by .product_list .item

Note, try using currentTarget

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement