Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the content of the html input text field using Jquery

I am having a html text field which can hide.

When hiding I want clear the text field.

I used this and it doesn't work.

$('#id').val("");

And I tried $('#id').text(""); as well.

It removed the whole text field.

like image 964
Yasitha Avatar asked Aug 13 '11 02:08

Yasitha


1 Answers

This is correct:

$('#id').val('');

However, your part 2 is interesting.

$('#id').text("");

That shouldn't create the behavior you're describing. I expect that you're referencing the parent object, not the <input> directly.

like image 65
John Green Avatar answered Sep 20 '22 14:09

John Green