Reputation: 335
I've tried this but it doesn't work:
$(function() {
$('input[type=text]').focus(function() {
$(this).val() == '';
});
});
Upvotes: 25
Views: 79119
Reputation: 475
A little late but another approach would be this
When you click the input box it will select all the text(not clear) only if it is the default value on the box. That way if a user types something then has to go back to edit it, it's not cleared which could be quite annoying!
Also selecting the text instead of clearing it reminds the user of the example. One to keep in mind i guess.
Upvotes: 4
Reputation: 114876
To set the value, you have to pass the new value as a parameter. This is a funky thing with the .val() jQuery function.
$(this).val('')
take a look at the jQuery API and search for 'val'
Upvotes: 75