function add() {
var txtNumber = document.getElementById("book");
var newNumber = parseInt(book.value) + 1;
book.value = newNumber;
}
function sub() {
var txtNumber = document.getElementById("book");
var newNumber = parseInt(book.value) - 1;
book.value = newNumber;
}
<div class="range">
<label>Book</label>
<a href="#" onClick="sub()">subtract</a><input type="text" id="book" value="0" min="0"><a href="#" onClick="add()"> Add</a>
</div>
<div class="range">
<label>Pen</label>
<a href="#" onClick="sub()">subtract</a><input type="text" id="pen" value="0" min="0"><a href="#" onClick="add()"> Add</a>
</div>
How to use same function for different Id's?
I tried using "this" keyword for selecting a current Id but it didn't work... and i am trying do this in javascript only instead of jquery.