Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  172] [ 1]  / answers: 1 / hits: 89698  / 6 Years ago, fri, july 27, 2018, 12:00:00

I have requirement to show and hide user password when click on eye icon so I had written script for that,when I click on eye icon only class is changing but password is not visible and again click on slash-eye icon it should hidden both these method not working how to solve this issue?



<input type=password name=player_password id=pass_log_id />

<span toggle=#password-field class=fa fa-fw fa-eye field_icon toggle-password></span>

<script>
$(body).on('click','.toggle-password',function(){
$(this).toggleClass(fa-eye fa-eye-slash);

var input = $(#pass_log_id).attr(type);

if (input.attr(type) === password) {
input.attr(type, text);
} else {
input.attr(type, password);
}
});
</script>

More From » jquery

 Answers
32

Your input is actually string. Check console, you should see that string does not have method attr() because you assign $().attr() to input





$(body).on('click', '.toggle-password', function() {
$(this).toggleClass(fa-eye fa-eye-slash);
var input = $(#pass_log_id);
if (input.attr(type) === password) {
input.attr(type, text);
} else {
input.attr(type, password);
}

});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<span toggle=#password-field class=fa fa-fw fa-eye field_icon toggle-password>Show/Hide</span>
<input type=password id=pass_log_id/>




[#53868] Tuesday, July 24, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;