Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery clear input[type=password]

I'm trying to clear all the inputs that are password type when jquery validation fails - I tried the following (which doesn't work) :

$('input[type=password]').val('');

Any ideas?

like image 350
user398341 Avatar asked Jul 02 '11 16:07

user398341


People also ask

How can we make input field empty in jQuery?

We can clear an input field using jQuery easily by making use of the jQuery val() method. We simply need to set the value of the input field to an empty string.


2 Answers

Try with

$("input[type='password']").val('');
like image 135
Felix Avatar answered Sep 23 '22 19:09

Felix


Try using the :password selector as it will make your code shorter:

$(':password').val('');

Also your initial code should work. Your problem is somewhere else. Unfortunately as you haven't stated in what context and how this is called or as you haven't explained what it doesn't work mean I cannot help you further.

like image 30
Darin Dimitrov Avatar answered Sep 20 '22 19:09

Darin Dimitrov