Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform input type text to password [duplicate]

Tags:

jquery

attr

I want to change the input type to password when I click on it. I tried this:

<input name="pin" id="cp_serv" type="text" class="pin_v" value="Insert PIN Please" onclick="this.value='';$(this).attr('type','password');"/>

I tried to use the jQuery function attr to change this on the click event, but nothing is happening.

Is this the right way to do it or is this possible?

like image 961
user2501504 Avatar asked Oct 24 '25 03:10

user2501504


1 Answers

This will work

$('input').on('click', function () {
   $(this).attr('type', 'password'); 
});

jsfiddle

Update

For IE read accepted answer for this post.

like image 138
26ph19 Avatar answered Oct 26 '25 23:10

26ph19



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!