For the sake of simplicity, we are going to increment and decrement by 1. We will use arithmetic operators addition (+) and subtraction (-) operators to achieve that.
In the following example, we have 2 buttons, one for increment and another for decrement. Depending upon which button is clicked, we will add or subtract 1 from the value in the input field. Please have a look over the code example and steps given below.
HTML & CSS
We have 4 elements in the HTML file and that includes div, 2 button, and input elements.
The div element is just a wrapper for the rest of the elements.
The inner text for the first button element is “-” and for the second button element, it is “+”.
We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.