Reputation: 7
$('#delete').click(function(){
return val.slice(0, -1);
});
I want to create a C button in my calculator which can delete last entered digit..
Upvotes: 1
Views: 135
Reputation: 74738
You can assign the new value after slicing:
$('#delete').click(function(){
var v = $('targetInput').val().slice(0, -1);
$('targetInput').val(v);
});
Upvotes: 0
Reputation: 115222
You can use val()
with callback function to update the value based on old value
$('#delete').click(function() {
$('#text').val(function(i, val) {
return val.slice(0, -1);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" id="text" />
<button id="delete">C</utton>
Upvotes: 1