function increment(value) {
var txtNumber = document.getElementById(value);
var newNumber = parseInt(txtNumber.value) + 1;
txtNumber.value = newNumber;
}
function decrement(value) {
var txtNumber = document.getElementById(value);
var newNumber = parseInt(txtNumber.value) - 1;
txtNumber.value = newNumber;
}
<div class="range">
<label>Book</label>
<a href="#" onClick="decrement('book')">subtract</a><input type="text" id="book" value="0" min="0"><a href="#" onClick="increment('book')"> Add</a>
</div>
<div class="range">
<label>Pen</label>
<a href="#" onClick="decrement('pen')">subtract</a><input type="text" id="pen" value="0" min="0"><a href="#" onClick="increment('pen')"> Add</a>
</div>
How can I use the same functions for different Id's?
I attempted to use the "this" keyword to select the current Id, but it did not work... and I am striving to accomplish this using JavaScript only instead of jQuery.