Hulk
Hulk

Reputation: 34170

Jquery field clear

All,

I have a text area field in my for,.How do i clear contents of it on sum onclick using jquery

Thanks.

Upvotes: 0

Views: 948

Answers (3)

eozzy
eozzy

Reputation: 68680

This will clear the default value onclick and restore back onblur.

$('textarea').click(function () {
    if (this.value == this.defaultValue) {
        this.value = '';
    }
});
$('textarea').blur(function () {
    if (this.value === '') {
        this.value = this.defaultValue;
    }
});

Upvotes: 2

David Hellsing
David Hellsing

Reputation: 108500

$('textarea').focus(function() {
  $(this).val('');
});

This will clear the textarea on focus (using mouse click or keyboard).

Upvotes: 3

mopoke
mopoke

Reputation: 10685

$("#textArea").click(function(){ $(this).attr({ value: '' }); });

With a couple of caveats:

  • it'll clear whenever someone clicks on it, even if they've entered data already
  • it'll only work if someone clicks on the field

Upvotes: 3

Related Questions