How To Show Password Onclick Of CheckBox Using JQuery

admin_img Posted By Bajarangi soft , Posted On 16-10-2020

In Jquery we can I hide and show password on click of checkbox .So today we discuss how to do it using jquery.

How To Show Password Onclick Of CheckBox Using JQuery

Step 1:Create index.html file and implement below code.
 

<input class="form-control" type='password' id='test-input' /> Show password <input type='checkbox' id='check' />


Step 2:Implement jQuery to hide and show password.
 

<script type='text/javascript'>
    $(document).ready(function(){
        $('#check').click(function(){
            alert($(this).is(':checked'));
            $(this).is(':checked') ? $('#test-input').attr('type', 'text') : $('#test-input').attr('type', 'password');
        });
    });
</script>



Complete Code For Showing Password Onclick Of CheckBox Using JQuery

 

<!DOCTYPE html>
<html>
<head>
    <title>How To Show Password Onclick Of CheckBox Using JQuery</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<style>
    body {
        background: black;
    }
</style>
<body>
<div class="container">
    <br><br><br><br>
    <div class="text-center">
        <h1 id="color" style="color: White;">Show Password Onclick Of CheckBox Using JQuery</h1>
    </div>
    <br>

    <div class="well">
        <input class="form-control" type='password' id='test-input' /> Show password <input type='checkbox' id='check' />
    </div>

</div>
</body>
</html>
<script type='text/javascript'>
    $(document).ready(function(){
        $('#check').click(function(){
            alert($(this).is(':checked'));
            $(this).is(':checked') ? $('#test-input').attr('type', 'text') : $('#test-input').attr('type', 'password');
        });
    });
</script>

Related Post