I try as following jquery code, but it doesn’t work true, how can fix it?
Demo: http://jsfiddle.net/pjqcf/
<input type="text" value="Some descriptive text...">
$('input[type=text]').focus(function () {
if ($(this).val() == $(this).attr('defaultValue')) {
$(this).val('');
}
});
$('input[type=text]').blur(function () {
if ($(this).val() == '') {
$(this).val($(this).attr('defaultValue'));
}
});
You haven’t set “defaultValue” attribute of your input. Set “defaultValue” to “Some descriptive text..” and it should work