i have this jquery code that alters the input fields value.
i would like to control its 'type' attribute.
this kind of works but it feels off,
is there a better way of handling this task?
Code:$('#password').live("click", function(){ if( $(this).val() == "Password" ) { $(this).val("").css({'color':'#000'}); }else{ $(this).css({'color':'#000'}); } var oldButton = $(this); var newButton = oldButton.clone(); newButton.attr("type", "password"); newButton.attr("id", "newPassword"); newButton.insertBefore(oldButton); oldButton.remove(); newButton.attr("id", "password"); }); $("#password").blur(function() { if( $(this).val() == "" ) { var oldButton = $(this); var newButton = oldButton.clone(); newButton.attr("type", "text"); newButton.attr("id", "newPassword"); newButton.insertBefore(oldButton); oldButton.remove(); newButton.attr("id", "password"); $(this).val("Password").css({'color':'#777'}); } });
RE: this did the trick
Code:$(this).get(0).type = 'password';



Reply With Quote
Bookmarks