Below Jquery is working fine but How could I shorten this Jquery? I have to show and hide the password for password and confirmed password? https://jsfiddle.net/c5cvLo54/1/
This is the shortest i think you can get
$(".confirm-password-showhide .trigger-password, .password-showhide .trigger-password").click(function() {
var c = $(this).parent().attr("class").replace("-showhide", "");
var obj = $("#" + (c.indexOf("confirm") > -1 ? "confirmPassword" : "password"));
obj.attr("type", obj.attr("type") == "text" ? "password" : "text");
$(this).text($(this).text() == "hide" ? "show" : "hide");
});
I've also removed the "hide" span from each of the passwords.
$(".confirm-password-showhide .trigger-password, .password-showhide .trigger-password").click(function() {
var c = $(this).parent().attr("class").replace("-showhide", "");
var obj = $("#" + (c.indexOf("confirm") > -1 ? "confirmPassword" : "password"));
obj.attr("type", obj.attr("type") == "text" ? "password" : "text");
$(this).text($(this).text() == "hide" ? "show" : "hide");
});
- Show
- Show