Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Attribute "type" from text to password

Tags:

jquery

Why isn't the jQuery changing the type attribute of #password_input to password?

<html>
    <head>
        <title></title>
        <style type="text/css">
        </style>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function() {
            $("#password_input").attr('type','password');
        });
        </script>
    </head>
    <body>
        <div id="loginBox">
            <form>
            <input type="text" id="username_input" name="username" /><br />
            <input type="text" id="password_input" name="password" />
            </form>
        </div>
    </body>
</html>
like image 589
AndrewFerrara Avatar asked Apr 10 '11 01:04

AndrewFerrara


1 Answers

Have you tried using .prop?

$("#password_input").prop('type','password');

http://api.jquery.com/prop/

like image 160
Mark Mckelvie Avatar answered Oct 24 '22 07:10

Mark Mckelvie