Reputation: 123
I am having an input field and a button. When I click the button, the input field should clear itself. My HTML is:
<input type="text" id="search_number" />
<button id="submit">Submit</button>
And the js is:
$('#submit').click(function(){
$('#search_number').value = '';
});
It doesnt works.. Thanks..
Upvotes: 0
Views: 97
Reputation: 35793
Use the val function to set the value. Passing in an empty string will clear the value:
$('#submit').click(function(){
$('#search_number').val('');
});
Also, the hash (#) was missing from the selector for search_number
Working example - http://jsbin.com/ilutar/1/
Upvotes: 2
Reputation: 45083
You need to properly specify that the selector for search_number
is an identifier (by prefixing with a #
(hash)), and use val()
instead (which will get the value if no value is specified, and set the value of one is):
$("#search_number").val("");
Upvotes: 3
Reputation: 49909
You have to do this:
$('#search_number').val("");
.value
with jQuery but .val()
Upvotes: 3