Question:
How can I change the value of css custom property by 1 on button click using jQuery?I want to change the value by 1 when the next button is clicked, I tried to use this x variable and then add one to it whenever the next button is clicked but it didn’t work. What should i do to get the code working, if I want the x variable to increase by 1 when i click on the next button.
Answer:
UseCSSStyleDeclaration.getPropertyValue()
to get the current --slider-index
value, assign to a variable, such as x
, and pre-increment it’s value, as in: ++x
.For example:
If you don’t need to use the
--slider-index
value in that code block again, you can skip assigning to a variable and just add one to the current --slider-index
value:If you have better answer, please add a comment about this, thank you!